JQuery Ajax帮助
我的站点上有一个页面,当前通过ajax加载html。JQuery是:JQuery Ajax帮助,jquery,Jquery,我的站点上有一个页面,当前通过ajax加载html。JQuery是: $(document).ready(function() { $('.projects a').click(function(event) { $('#work').load(this.href); event.preventDefault(); }); })) html是: <div class="projects"> <a href="work/link.html" title=
$(document).ready(function() {
$('.projects a').click(function(event) {
$('#work').load(this.href);
event.preventDefault();
});
}))
html是:
<div class="projects">
<a href="work/link.html" title="blah" id="blah">blah</a>
<a href="work/link1.html" title="blah" id="blah">blah</a>
<a href="work/link2.html" title="blah" id="blah">blah</a>
</div>
这很好,但是我的要求已经改变了。我想把我正在加载的页面的某个区域拉到#work div中。所以我想说什么时候单击.project a将#this div的内容从this.href加载到#work中。有人能给我指一下正确的方向吗?看看这一部分。通过向url字符串添加选择器,可以将要加载的页面部分作为目标
$(document).ready(function() {
$('.projects a').click(function (event) {
jQuery.get(this.href, function (response) {
$('#work').empty().append($(response).find('#myDiv'));
});
});
event.preventDefault();
});
.load()方法,与$.get()不同,
允许我们指定
要插入的远程文档。这
是通过一种特殊的语法实现的
url参数。如果一个或多个
空格字符包含在
字符串,字符串的一部分
假设在第一个空格之后
要成为jQuery选择器
确定要加载的内容
$(“#result”).load('ajax/test.html#container')
当这个方法执行时,它
检索的内容
ajax/test.html,但jQuery会解析
返回的文档以查找
ID为container的元素。这
元素及其内容是
插入到具有ID的元素中
结果如何,剩下的
检索到的文档将被丢弃
$('#work').load(this.href + ' #this');