在另一页上加载div的内容

Rob*_*ght 22 html hash jquery load

您将从此代码中看到它从哈希标记加载内容URL.无论如何只从该外部页面加载一个div元素.

$(function() {
    if(location.hash) $("#content_inload").load(location.hash.substring(1)); 
    $("#nav a").click(function() {
            $("#content_inload").load(this.hash.substring(1));
    });
});
Run Code Online (Sandbox Code Playgroud)

所以像之后的事情 .substring(#inload_content(1))

但这不起作用.

谢谢

Rad*_*adu 54

你只需要在url后面添加一个jquery选择器.

请参阅:http://api.jquery.com/load/

直接来自API的示例:

$('#result').load('ajax/test.html #container');
Run Code Online (Sandbox Code Playgroud)

那么它的作用是从指定的url加载#container元素.


Zac*_*oom 11

是的,请参阅http://api.jquery.com/load/上的"加载页面碎片" .

简而言之,您在URL后添加选择器.例如:

$('#result').load('ajax/test.html #container');
Run Code Online (Sandbox Code Playgroud)