在ie11中收到此错误:无法获取属性'选项'未定义或空引用

时间:2017-05-05 02:29:10

标签: internet-explorer-11



function run(event) {
console.log(document.getElementById("user").label);
var lable=event.target.options[event.target.selectedIndex].parentNode.label;
    if(lable == 'user'){
      document.getElementById("copy").value = "user";
    } else if (lable == 'warehouse') {
    	document.getElementById("copy").value = "warehouse";
    } else if (lable == 'dollhouse') {
    	document.getElementById("copy").value = "dollhouse";
    }
}

<form>
<select name="sel" id="sel" onchange="run(event)">
<option selected disabled>Wybierz...</option>
  <optgroup id="user" value="user" label="user">
    <option value="1">michal</option>
    <option value="2">mateusz</option>
  </optgroup>
  <optgroup id="warehouse" value="warehouse" label="warehouse">
    <option value="1">kosz</option>
    <option value="2">zaginione</option>
  </optgroup>
  <optgroup id="dollhouse" value="dollhouse" label="dollhouse">
    <option value="1">muiy</option>
    <option value="2">goey</option>
  </optgroup>
</select>
</form>
<input type="text" name="copy" id="copy">
&#13;
&#13;
&#13;

需要帮助在IE11中使用它,在chrome中运行良好。获得无法获得财产的选项&#39;未定义或空引用&#39;

1 个答案:

答案 0 :(得分:0)

<meta http-equiv="X-UA-Compatible" content="IE=8" />

这可能会有所帮助,或者您可以查看此问题和答案。 SCRIPT5007: Unable to get property 'value' of undefined or null reference