我想获取一个页面,然后使用 jquery 查找链接等元素。如何让 $('#blah') 搜索获取数据而不是页面?
最佳答案
您应该能够从返回的 HTML 创建一个 dom 元素,而无需将其实际添加到文档中,然后使用 jQuery 方法进行搜索:
jQuery.get('/my_url/', function(html_data) {
// If your html_data isn't already wrapped with an HTML object, you may
// need to wrap it like so:
//
// var jQueryObject = $("<div>" + html_data + "</div>");
var jQueryObject = $(html_data);
jQueryObject.find("a.link_class");
// Or, as stated by gregmac below, you could just do the following:
$("a.link_class", html_data);
// or, if wrapping is required:
$("a.link_class", "<div>" + html_data + "<div>");
});
关于javascript - 我如何在 $.get(url) 的项目上使用 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2509659/