javascript 具有特定 ID 的 Jquery .load 元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7747487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery .load element with specific id?
提问by Shahmeer Navid
jQuery("#menu li a").click(function(){
var page_url = jQuery(this).attr("href")
jQuery(".wide_main").html("<p>loading...</p>");
jQuery(".wide_main").load( page_url + '#main_content');
});
I have this code but it just loads the entire requested page instead of just the #main_content div.
我有这个代码,但它只是加载整个请求的页面,而不仅仅是#main_content div。
Thanks.
谢谢。
回答by genesis
try to add space between url and #main_content
尝试在 url 和 #main_content 之间添加空格
jQuery(".wide_main").load( page_url + ' #main_content');
回答by BVSmallman
The jQuery example for doing this is:
执行此操作的 jQuery 示例是:
$('#result').load('ajax/test.html #container');
It appears it is because you are missing a space after the file and before the container.
看来这是因为您在文件之后和容器之前缺少一个空格。