Jquery 将html的部分加载到div中

Jquery 将html的部分加载到div中,jquery,Jquery,有没有办法使用jQuery只将外部html文件的预定部分加载到div中 如果外部html被细分(例如使用)为单独的部分,jQuery是否可以仅提取div id=“section1”并将其输出到目标div中 我可以调整这段代码来实现这一点吗 $(document).ready(function () { $.ajax({ url : "sourceFile.html", dataType : "html", success : functi

有没有办法使用jQuery只将外部html文件的预定部分加载到div中

如果外部html被细分(例如使用
)为单独的部分,jQuery是否可以仅提取div id=“section1”并将其输出到目标div中

我可以调整这段代码来实现这一点吗

$(document).ready(function () {

    $.ajax({
        url : "sourceFile.html",
        dataType : "html",
        success : function (data) {
            $("#targetDIV").html(data);
        },
        error : function (XMLHttpRequest, textStatus, errorThrown) { 
            alert("doc did not load. Status: " + textStatus);
            alert("doc did not load. Error: " + errorThrown); 
        }
    });

});
使用
.load

$("#targetDIV").load("sourceFile.html #section1");
在文件名后包含一个空格,其中包含您希望从该文件中获取的特定内容。API: