本文介绍了JQuery的在Internet Explorer不能解析字符串的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分析的基础上使用jQuery,在Internet Explorer中的HTML字符串:解析使用Ajax / jQuery的的HTML字符串。这里是code:

I am trying to parse an HTML string in Internet Explorer using jQuery, based on: Parsing HTML String with Ajax/jQuery.here is the code:

alert(result);
alert($(result));

第一个警报提示HTML,但第二个警告只是给了我对象。在萤火精简版控制台它给了我一个空白的对象:[] !!

The first alert prompts the HTML, but second alert just gives me Object. On firebug lite console it gives me a blank object: [] !!

console.log(result)
console.log($(result))

结果是一个很大的XHTML code,即通过AJAX调用接收。同样的code工作在Firefox。

result is a big XHTML code, that is received through an AJAX call.The same code works on Firefox..

任何人有任何想法,为什么这可能是发生?你的帮助是非常AP preciated ..!

Anyone has any idea why this could be happening?Your help is much appreciated..!

推荐答案

在没有看到HTML code,这很难说,但我会猜你打的的未知的运行时错误的,当你无效地试图把它是不允许的元素出现。

Without seeing the HTML code, it's hard to say, but I would have to guess that you're hitting the "Unknown runtime error" that occurs when you're invalidly trying to put an element where it's not allowed.

您看到的,jQuery的创建一个分离元件和应用(X)HTML该元素的的innerHTML 属性构建从(X)HTML DOM中。 FWIW,无论是浏览器关心,如果你传递XHTML或HTML,除非你服务,将是给你更大的问题是XHTML MIME类型。如果你考虑以下纯JS code:

You see, jQuery builds the DOM from (X)HTML by creating a detached element and applying the (X)HTML to that element's innerHTML property. FWIW, neither browsers care if you're passing XHTML or HTML, unless you're serving an XHTML mime type that would be giving you bigger problems. If you consider the following plain JS code:

var p = document.createElement("p");
p.innerHTML = "<li>Test</li>";

Internet Explorer中抛出一个非常无益的未知的运行时错误的,而Firefox将尽最大努力抢救无效HTML。

Internet Explorer with throw a very unhelpful "Unknown runtime error", whereas Firefox will do its best to salvage the invalid HTML.

我会建议把你的XHTML通过 W3C验证并检查它的验证错误。

I would recommend putting your XHTML through the W3C Validator and checking it for validation errors.

这篇关于JQuery的在Internet Explorer不能解析字符串的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:29