javascript innerhtml不会更改源代码上的内容 [英] javascript innerhtml does not change content on source code
本文介绍了javascript innerhtml不会更改源代码上的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何解决这个问题。我想在某些事件上更改(DOM)源代码,如下所示:
I don't know how to solve this. I want to change the (DOM)source code on some event, like this:
脚本:
<script type="text/javascript">
function ChangeText(){
document.getElementById("p1").innerHTML="New text!";
}
</script>
html:
<p id="p1">Hello world!</p>
<input type="button" onclick="ChangeText()" value="Change text" />
当我点击按钮时,这个工作正常。但是当我查看源代码时,它仍然看起来像这样:
well, this works fine when I click the button. but when I view the source code.it still looks the same like this:
<html>
<body>
<p id="p1">Hello world!</p>
<input type="button" onclick="ChangeText()" value="Change text" />
</body>
</html>
而不是:
<html>
<body>
<p id="p1">New text!</p>
<input type="button" onclick="ChangeText()" value="Change text" />
</body>
</html>
推荐答案
您的源代码不会更改。
Your source code does not change.
只是DOM
因此,如果你使用的是firebug或chrome,你可以使用inspect元素来查看更改。
So if you are using firebug or chrome, you could use inspect element to see the change.
请参阅此处: http://jsfiddle.net/maniator/eVw7Y / (这是使用你的例子)
See here: http://jsfiddle.net/maniator/eVw7Y/ (this is using your example)
这篇关于javascript innerhtml不会更改源代码上的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文