使用JavaScript获取原始的html代码 [英] Use javascript to get raw html code

查看:126
本文介绍了使用JavaScript获取原始的html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,如果元素中的实际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&nbsp;fix"

Running this javascript getElementById('myE').innerHTML gives me "How to fix" which is the decoded form

How can I get "How to&nbsp;fix" using javascript?

解决方案

What you have should work:

Element test:

<div id="myE">How to&nbsp;fix</div>​

JavaScript test:

alert(document.getElementById("myE​​​​​​​​").innerHTML); //alerts "How to&nbsp;fix"

You can try it out here. Make sure that wherever you're using the result isn't show &nbsp; 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屋!

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