Load content of a div on another page

流过昼夜 提交于 2019-11-26 02:38:13

问题


You will see from this code that it loads the content URL from the hash tag. Is there anyway to load only a single div element from that external page.

$(function() {
    if(location.hash) $(\"#content_inload\").load(location.hash.substring(1)); 
    $(\"#nav a\").click(function() {
            $(\"#content_inload\").load(this.hash.substring(1));
    });
});

so something like after .substring(#inload_content(1))

but that does not work.

Thanks


回答1:


You just need to add a jquery selector after the url.

See: http://api.jquery.com/load/

Example straight from the API:

$('#result').load('ajax/test.html #container');

So what that does is it loads the #container element from the specified url.




回答2:


Yes, see "Loading Page Fragments" on http://api.jquery.com/load/.

In short, you add the selector after the URL. For example:

$('#result').load('ajax/test.html #container');


来源:https://stackoverflow.com/questions/4101770/load-content-of-a-div-on-another-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!