Hello World!

对jquery的一次封装 以方便jquery ui调用iframe框架页面

注意:首先你需要现引用jquery和jquery ui到页面,本次是对jquery ui的一次简单封装 以方便调用 iframe,仅此而已,没考虑其他的。

 1  (function ($) {
 2           var  show=function (ops) {
 3               var $obj = $('<iframe id="iframeshow" class="iframeshow" style="display:none" ></iframe>');
 4               $obj.appendTo($('body'));
 5               var url = ops.url;
 6               if (url.indexOf("?") > -1) url += "&r=" + Math.random();
 7               else url += "?r=" + Math.random();
 8               $obj.attr("src", url);
 9               $obj.dialog({
10                   autoOpen: true,
11                   modal: true,
12                   title: ops.title,
13                   width: ops.width,
14                   height: ops.height
15               });
16               $obj.css({ "margin": "0", "padding": "0", "width": "100%", "height": "" + ops.height + "px", "display": "block" });
17             }
18            var closeIframe=function (ops,callback) {
19                 var $obj = $('#iframeshow');
20                 $obj.dialog("close");
21                 $obj.remove();
22                 if(callback!=null)callback();
23             }
24               var defaults={
25                     title:"",
26                     url:"###",
27                     width:400,
28                     height:300
29                 };
30              $.extend({
31                  iframeshow:function(ops){
32                     var options=jQuery.extend(defaults,ops);
33                     show(options);
34                  },
35                  iframeclose:function(ops,call){
36                     closeIframe(ops,call);
37                  }
38              });
39         })(jQuery);

调用就很简单啦,

显示窗口:

 $.iframeshow({
                title: "添加新闻",
                url: "iframe/a.aspx",
                width: 550,
                height: 260
                        });

关闭:

$.iframeclose();

如图:不要嫌丑啊 ,呵呵 :-)

posted @ 2012-06-22 12:54  世界万物  阅读(403)  评论(0编辑  收藏  举报
Bye World!