zoukankan      html  css  js  c++  java
  • 使用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来引入了是不是 看官儿!!!

  • 相关阅读:
    AI CV 会议2018
    ubuntu 更改默认亮度
    ubuntu安装latex
    过滤文件代码 python
    ubuntu安装pycharm桌面快捷方式
    Ubuntu 14.04 鼠标消失解决方案
    ffmpeg常用命令
    FFMPEG 在ubuntu下的安装与使用
    pragma once
    chrono--高精度计时
  • 原文地址:https://www.cnblogs.com/yeminglong/p/12190905.html
Copyright © 2011-2022 走看看