我正在使用jquery作为xml解析器(大错误)。但是,我现在投入了太多资金来切换。我在jQuery自动转义<style>标记内容方面遇到问题。

var a = $("<style><foo>content</foo></style>"),
    b = $("<bar><foo>content</foo></bar>");

b.find('foo').length // => 1
a.find('foo').length // => 0

b.html() // => '<foo>content</foo>'
a.html() // => 'foo>content</foo>'
         //     ^--- missing '<'

b.text() // 'test'
a.text() // 'foo>content</foo>'


有没有一种方法可以防止jQuery这样做?

最佳答案

您可以使用:

var xml = jQuery.parseXML("<style><foo>content</foo></style>");
var a = $(xml);


为了防止jQuery区别对待style标签。

这是一个演示:http://jsfiddle.net/FABmh/

关于javascript - jQuery转义<style>内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15098298/

10-10 23:12
查看更多