IE 11 错误消息 - 由于错误 800a025e 无法完成操作

IE 11 Error message - Could not complete the operation due to error 800a025e

我在 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>

仅针对 IE 11 浏览器复制 ->JsFiddle example

查看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!");
  }
}