[英]How to get current html of a dom element
I am trying to retrive html of a dom element "abc". 我正在尝试检索dom元素“ abc”的html。
<div id=abc>
<input id=xyz type=text value="2" />
</div>
<input type=button value="2" onclick="show()"/>
<script>
document.getElementById("xyz").value=5;
function show(){
alert(document.getElementById("abc").innerHTML);
}
</script>
Lets say I modified the value of text box 可以说我修改了文本框的值
by Javascript code 通过Javascript代码
document.getElementById("xyz").value=5; 。的document.getElementById( “XYZ”)值= 5;
but 但
alert(document.getElementById("abc").innerHTML);
always show me 总是告诉我
<input id=xyz type=text value="2" />
Why? 为什么? Can anyone tell me how I can get the latest html of the dom element "abc".?
谁能告诉我如何获取dom元素“ abc”的最新html。
.value will not change the HTML. .value不会更改HTML。 If you want to do that, use .setAttrubute instead.
如果要这样做,请改用.setAttrubute。 See this JSFiddle: http://jsfiddle.net/5EFXN/
看到这个JSFiddle: http : //jsfiddle.net/5EFXN/
document.getElementById("xyz").setAttribute('value','5');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.