none
IE10和JS的兼容性问题 RRS feed

  • 问题

  • 有段代码是这样的:

    DispAddressPrefecture.value = AddressPrefecture.options[AddressPrefecture.selectedIndex].text

    在IE10以下的版本的浏览器,都是正常的,在IE10这种写法会不兼容吗?

    现在的状况是,在这句话之前打alert,都可以正常显示,到了这一句就出不来了。

    2014年1月22日 8:17

答案

  • Hi,

    You can try this code:

    <script type="text/javascript">
            function fnChange() {
                var s = document.getElementById("oCars");
                var d = document.getElementById("oData");
                d.value = s.options[s.selectedIndex].text;
                alert("sdf");
                s.options[s.options.length] = new Option("Option text", "optionValue");//work
                
                oData.value += oCars.options[oCars.selectedIndex].text + "\n";//undefined oData error
            }
    
        </script>

     <select id="oCars" onchange="fnChange()" size="1">
      <option value="1">BMW</option>
      <option value="2">PORSCHE</option>
      <option selected="" value="3">MERCEDES</option>
    </select>
    <textarea id="oData"></textarea>
    I test it in ie11. So you can try using document.getElementById("oData") instead of "oData". It should work.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    2014年1月23日 2:37