document.getElementById().value and document.getElementById().checked not working for IE

前端 未结 4 1841
礼貌的吻别
礼貌的吻别 2020-12-30 23:29

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). Does anyone know what is wr

4条回答
  •  时光取名叫无心
    2020-12-31 00:03

    Jin Yong - IE has an issue with polluting the global scope with object references to any DOM elements with a "name" or "id" attribute set on the "initial" page load.

    Thus you may have issues due to your variable name.

    Try this and see if it works.

    var someOtherName="abc";
    //  ^^^^^^^^^^^^^
    document.getElementById('msg').value = someOtherName;
    document.getElementById('sp_100').checked = true;
    

    There is a chance (in your original code) that IE attempts to set the value of the input to a reference to that actual element (ignores the error) but leaves you with no new value.

    Keep in mind that in IE6/IE7 case doesn't matter for naming objects. IE believes that "foo" "Foo" and "FOO" are all the same object.

提交回复
热议问题