我通过 $.get() 加载一些 HTML;我只想将结果的某些部分插入到我的 html 中。于是搜索发现this questions然后尝试了这个:
$("a.load").click(function() {
$.get(this.href, {}, function(result) {
content = $("#main", result);
console.log(content);
}, "html");
return false;
});
虽然 result
具有正确的内容,但 console.log(content)
返回 []
。有人知道我做错了什么吗?
提前致谢!
最佳答案
如果您正在尝试做听起来像您所做的事情,.load()会更容易:
$("a.load").click(function() {
$("#WhereYouWantHTMLInjected").load(this.href + ' #main');
return false;
});
关于jquery - 使用 jQuery 遍历 $.get() 的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4456265/