Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

javascript - document.getElementById()。value和document.getElementById()。选中不适用于IE(document.getElementById().value and document.getElementById().checked not working for IE)

I tried to assign a new value into the hidden input and checkbox of an input form.

(我尝试将新值分配给输入表单的隐藏输入和复选框。)

It's working fine in Firefox but not in IE (I'm using IE 7).

(它在Firefox中工作正常,但在IE中却没有(我使用的是IE 7)。)

Does anyone know what is wrong with my code?

(有谁知道我的代码有什么问题?)

HTML:

(HTML:)

<input type="hidden" id="msg" name="msg" value="" style="display:none"/>
<input type="checkbox" name="sp" value="100" id="sp_100">

Javascript:

(使用Javascript:)

var Msg="abc";
document.getElementById('msg').value = Msg;
document.getElementById('sp_100').checked = true;
  ask by Jin Yong translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For non-grouped elements, name and id should be same.

(对于非分组元素,name和id应该相同。)

In this case you gave name as 'sp' and id as 'sp_100'.

(在这种情况下,您将名称命名为“sp”,将id命名为“sp_100”。)

Don't do that, do it like this:

(不要这样做,这样做:)

HTML:

(HTML:)

<input type="hidden" id="msg" name="msg" value="" style="display:none"/>
<input type="checkbox" name="sp" value="100" id="sp">

Javascript:

(使用Javascript:)

var Msg="abc";
document.getElementById('msg').value = Msg;
document.getElementById('sp').checked = true;

For more details

(更多细节)

please visit : http://www.impressivewebs.com/avoiding-problems-with-javascript-getelementbyid-method-in-internet-explorer-7/

(请访问: http//www.impressivewebs.com/avoiding-problems-with-javascript-getelementbyid-method-in-internet-explorer-7/)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...