gpt4 book ai didi

JQuery Ajax 帮助

转载 作者:行者123 更新时间:2023-12-01 00:59:30 25 4
gpt4 key购买 nike

我的网站上有一个页面当前通过 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="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 中。谁能指出我正确的方向?

最佳答案

看看Loading Page Fragments部分。您可以通过向 URL 字符串添加选择器来定位要加载的页面部分。

The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. This is achieved with a special syntax for the url parameter. If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded.

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

When this method executes, it retrieves the content of ajax/test.html, but then jQuery parses the returned document to find the element with an ID of container. This element, along with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded.

$('#work').load(this.href + ' #this');

关于JQuery Ajax 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2729629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com