为什么这个jQuery无法加载/解析我的HTML字符串? [英] Why does this jQuery fail to load/parse my HTML string?

查看:188
本文介绍了为什么这个jQuery无法加载/解析我的HTML字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

($ data)。$($ data)
alert(data);
alert($(data).html() );
});

第一个弹出窗口是所有HTML都很好,很健康的。

第二个弹出窗口是空白的。为什么? (HTML是符合XHTML的)

解决方案

documentation :


HTML字符串不能包含
元素它们在
div内无效,例如html,head,body或
标题元素。


如果您正在获取完整的HTML文档,那么您将拥有很多可能不会出现在div中的元素。


jQuery.get(window.location.href, function(data) {
  alert(data);
  alert($(data).html());
});

The first popup is all the HTML good and healthy.

The second popup is blank. Why? (the HTML is XHTML compliant)

解决方案

From the documentation:

The HTML string cannot contain elements that are invalid within a div, such as html, head, body, or title elements.

If you are fetching a complete HTML document, then you will have lots of elements that may not appear in a div.

这篇关于为什么这个jQuery无法加载/解析我的HTML字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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