• 使用jquery的load方法只加载body之间的内容


    使用jquery的load方法只加载body之间的内容。首先我们提取了$.fn.load.toString()得到了它的源码,然后在源码的基础上做出修改。如下:

    $.fn.load = function (a, b, c) {
            if ("string" != typeof a && bc) return bc.apply(this, arguments);
            var d, e, f, g = this, h = a.indexOf(" ");
            return h >= 0 && (d = $.trim(a.slice(h, a.length)), a = a.slice(0, h)), $.isFunction(b) ? (c = b, b = void 0) : b && "object" == typeof b && (f = "POST"), g.length > 0 && $.ajax({
                url: a,
                type: f,
                dataType: "html",
                data: b
            }).done(function (a) {
                // 提取body部分
                var pattern = /<body[^>]*>((.|[
    
    ])*)</body>/im;
                var matches = pattern.exec(a);
                if (matches) {
                    a = matches[1]
                }
                // 提取body部分
                e = arguments, g.html(d ? $("<div>").append($.parseHTML(a)).find(d) : a)
            }).complete(c && function (a, b) {
                g.each(c, e || [a.responseText, b, a])
            }), this
        }

     

     这样我们就可以ajax加载另外一个界面的body之间的内容,为什么呢?因为一个HTML中只允许有一个body标签,要不然就需要iframe来引入了是不是 看官儿!!!

  • 相关阅读:
    为Internal页面添加一个Unit Test的运行入口
    使用 AWSTATS 来查看IIS/iisnode 日志
    用issnode+IIS来托管NodeJs Server之四:支持Debug
    Restify实践
    Mocha实践
    Graphite实战
    StatsD与Graphite联合作战
    单元测试
    NHibernate配置
    NHibernate概念
  • 原文地址:https://www.cnblogs.com/yeminglong/p/12190905.html
Copyright © 2020-2023  润新知