0
.load('test.html #example')

如何在没有包装器的情况下返回#example's 的内容?<div id="example">

4

2 回答 2

3

使用 jQuery.get()代替加载。

使用它的回调函数来操作返回的数据:

$.get('test.html', function(data) {
  alert($(data).find('#example').html());
});
于 2013-07-08T00:02:08.473 回答
1

.load()应该接受任何可以用 sizzle 解析的选择器:

.load('test.html #example > *')

从文档:

如果字符串中包含一个或多个空格字符,则假定字符串中第一个空格之后的部分是确定要加载的内容的 jQuery 选择器。

于 2013-07-08T00:02:52.923 回答