我如何可以查询HTML多数民众赞成从阿贾克斯回来?
How can I query HTML thats returned from AJAX?
我试过
$.post("gethtml.php", { url: $url.val() }, function(data) {
var $html = $(data),
$links = $("link, script, style", $html),
$body = $("body", $html);
$links.each(function() { $(this).addClass("tmp"); });
console.log($html);
console.log($body.html());
});
$ HTML
看起来像 [元,标题,文字,样式#gstyle,脚本,文本区域#CSI,DIV#mngb,iframe中,中心,脚本,脚本]
和 $ body.html()
空
更新
有一个简单的设置在 http://jsfiddle.net/uvnrJ/1/
$(function() {
var html = "<!doctype html><html><head><title>title here ... </title></head><body>This is the body</body></html>",
$html = $(html);
console.log($html); // jQuery(title, <TextNode textContent="This is the body">)
console.log($html.find("body")); // jQuery()
console.log($html.find("title")); // jQuery()
console.log($html.filter("title")); // jQuery(title)
});
可见,jQuery的似乎有解析HTML字符串的问题?
Shows that jQuery seem to have problems parsing the HTML string?
试试这个...
..........
var elements = $('<div></div>');
elements.html(data);
alert(elements.find('body').html());
...........