我正在尝试使用 jQuery 在单击按钮时重新加载特定元素,但是当我单击该按钮时,整个页面都会加载到该元素中。我尝试了以下代码,它在这个元素中加载了整个页面。我只想加载特定元素。
$(document).ready(function() {
$("#button").click(function() {
$("#demo").load(location.href + "#demo");
});
});
<div id="example">
<p id="demo">hi</p>
<button id="button" type="button">press</button>
</div>
最佳答案
您可以使用 load()
带选择器。
$("#demo").load(location.href + " #demo"); // Add space between URL and selector.
^
这将仅从 location.href
URL 加载 #demo
元素。
关于javascript - 使用 jQuery 重新加载特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36590722/