我在IE 11中收到以下错误消息: 由于错误800a025e无法完成操作。
调用range.select()时会抛出此错误
function ExtendSelection() {
var sel;
if (document.body.createTextRange) { // Internet Explorer
var range = document.body.createTextRange();
range.moveStart('character', 0);
range.collapse(true);
range.moveStart('character', 29); //causes an exception
//range.moveStart('character', 30);//No exception
range.moveEnd('character', 177);
range.select();
alert(range.text);
} else {
alert("Your browser does not support this example!");
}
}

<button onclick="ExtendSelection ()">Click to reproduce the error</button>
<a >
<span>
<div>
<select>
<option>CopyTo:</option>
<option>Headnote</option>
<option>Synopsis</option>
<option>Statute</option>
</select>
</div>
</span>
</a>
<a>
<span>Pages: 8 - 8</span>
</a>
<a>
<span>nortlaw</span>
</a>
<input>
&#13;
仅针对IE 11浏览器进行复制 - &gt; JsFiddle example
答案 0 :(得分:3)
查看Microsoft's documentation on TextRange,似乎collapse()
方法不存在。我删除了那个电话,错误就消失了。
function ExtendSelection() {
var sel;
if (document.body.createTextRange) { // Internet Explorer
var range = document.body.createTextRange();
range.moveStart('character', 0);
// range.collapse(true); <-- IE does not understand this line
range.moveStart('character', 29); //causes an exception
// range.moveStart('character', 30);//No exception
range.moveEnd('character', 177);
range.select();
alert(range.text);
} else {
alert("Your browser does not support this example!");
}
}