admin管理员组文章数量:1401171
I am trying to set dynamically innerHTML for value tag in IE.
The output I expect is this.
<input type="hidden" >a0FQ0000009rJfCMAU</input>
I tried innerHTML in IE but it was not working since it is supported for INPUT element. So, I tried the following out of desperation.
myElementId.setAttribute("value",textNodeId);
Unfortunately this is not what I want.
<input type="hidden" value="a0FQ0000009rJfCMAU">
Please advise.
I am trying to set dynamically innerHTML for value tag in IE.
The output I expect is this.
<input type="hidden" >a0FQ0000009rJfCMAU</input>
I tried innerHTML in IE but it was not working since it is supported for INPUT element. So, I tried the following out of desperation.
myElementId.setAttribute("value",textNodeId);
Unfortunately this is not what I want.
<input type="hidden" value="a0FQ0000009rJfCMAU">
Please advise.
Share Improve this question asked Nov 21, 2011 at 12:26 bragboybragboy 35.6k30 gold badges116 silver badges175 bronze badges 4-
1
Do
<input>
elements even support CDATA? I think not. – Linus Kleen Commented Nov 21, 2011 at 12:29 - 2 If the input is hidden, why does it need to be innerHTML and not value? – user479870 Commented Nov 21, 2011 at 12:30
- @pdknsk : Good question which i don't have an answer.. the piece of code i've given is a sample of an existing framework/library. – bragboy Commented Nov 21, 2011 at 12:32
- 1 Why are you wanting to do this? The hidden type of input element does not support innerHTML, nor should it. a hidden element should always have it's value in the value field which you can access by using myElementId.value(textNodeId); – kamui Commented Nov 21, 2011 at 12:33
2 Answers
Reset to default 3If you check the input
element's specification, you see that its Content Model should be empty. Thus, what you try to find is logically invalid HTML.
See here.
If you want to change or set the value of input tag dynamically, you have to first define its name or id and then in javascript you can set it like
var txt = document.getElementById('yourtext');
txt.value = 'new value';
I hope this helps you.
本文标签: javascriptHow to set a inner value for Input tag in HTML in IEStack Overflow
版权声明:本文标题:javascript - How to set a inner value for Input tag in HTML in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744300886a2599574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论