查询HTML的AJAX返回 [英] Query HTML returned from AJAX

查看:104
本文介绍了查询HTML的AJAX返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以查询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());
...........

这篇关于查询HTML的AJAX返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆