当检查是否选择了多个选择索引时,出现SCRIPT ERROR 70

SCRIPT ERROR 70 when checking if a multiple select index is selected IE11

本文关键字:选择 出现 SCRIPT ERROR 是否 检查 索引      更新时间:2023-09-26

w/我有一个多重选择,列出一个州的县:

<select name="SAcounty" id="SAcounty" size="7" class="" multiple  onchange="getcities();" tabindex="47" style="font-size: 10px; color: black">
                        </select>

事件函数getcities在您第一次选择县时工作得很好。但是当你切换到另一个国家时,我得到permission denied error。

for (var i = 0; i < document.getElementById('SAcounty').length; i++) {
        if (document.getElementById('SAcounty').options[i].selected) {
            k = k + 1;
        }
    }

的行出现错误
    if (document.getElementById('SAcounty').options[i].selected)

这个工作完美之前,我们移动到IE 11没有比较模式,但现在没有我改变是解决这个错误。

似乎直到……才出现问题。被选中"。我可以设置一个变量document.getElementById(' sounty ')。选项[i]没有问题,但一旦。selected被添加....错误。

页面包含在一个框架中,但所有的功能都包含在同一个框架中,并且不与任何其他框架发生交互。

帮忙吗?

我已经创建了这个堆栈代码片段,显示了当我这样做时所看到的内容。

var el = document.getElementById('SAcounty');
el.options[5].selected = true;
for (var i = 0; i < el.options.length; i++) {
  var option = el.options[i];
  if (option.selected) {
    alert(option.text);
  }
}
<select multiple id="SAcounty">
  <option>1</option>
  <option>2</option>
  <option selected>3</option>
  <option>4</option>
  <option>5</option>
  <option>6</option>
</select>

这会提醒"3",然后在IE11中提醒"6"。