jquery html() is decoding html entities by default?

笑着哭i 提交于 2020-01-02 07:53:13

问题


I dont know why on earth jquery html() is doing this, but after i do

$('html').html()

i get "&copy" automatically converted to ©

anyway to avoid this? I need to dump the html of the page using javascript and dont need this useless conversions that are screwing up the html.


回答1:


This really isn't the jQuery, or even JavaScript for that matter.

The browser will hold its own normalised representation of the underlying DOM. It will bear a close resemblence the the document itself, but character decoding (like the above) will be preserved.

Have a read of the following:

http://www.brainjar.com/dhtml/intro/

http://bytes.com/topic/javascript/answers/146257-body-innerhtml-issue

I'm afraid there is no way around this as far as I am aware.




回答2:


jQuery should not. check what you really get using in FF firebug.

console.log($('html').html());


来源:https://stackoverflow.com/questions/4283434/jquery-html-is-decoding-html-entities-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!