使用JavaScript获取原始的html代码 [英] Use javascript to get raw html code
问题描述
例如,如果元素中的实际HTML代码是How to& nbsp; fix
运行此javascript
getElementById('myE')。innerHTML 给我如何解决
这是解码后的表格
如何获得How to& nbsp; fix
using javascript?
工作:
元素测试:
< div id = myE> How to& nbsp; fix< / div>
JavaScript测试:
alert(document.getElementById(myE).innerHTML); // alertHow to& nbsp; fix
你可以在这里试试。确保无论你在哪里使用,结果都不会显示& nbsp;
作为空格,情况可能如此。如果您想在某处为HTML设计的地方展示它,则需要将其转义。
I need to get the actual html code of an element in a web page.
For example if the actual html code inside the element is "How to fix"
Running this javascript
getElementById('myE').innerHTML gives me "How to fix"
which is the decoded form
How can I get "How to fix"
using javascript?
What you have should work:
Element test:
<div id="myE">How to fix</div>
JavaScript test:
alert(document.getElementById("myE").innerHTML); //alerts "How to fix"
You can try it out here. Make sure that wherever you're using the result isn't show
as a space, which is likely the case. If you want to show it somewhere that's designed for HTML, you'll need to escape it.
这篇关于使用JavaScript获取原始的html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!