2013-02-13 32 views
0

我需要相當於在Internet Explorer中getRangeAt()方法的版本9什麼等同於IE <9中的getRangeAt()方法?

if (window.getSelection) { 
    sel = window.getSelection(); 
    if (sel.rangeCount) { 
     range = sel.getRangeAt(0); 
    } 
} else if (document.selection && document.selection.createRange) { 
    // What shall I write here to do the same thing in IE before version 9 
} 


var table = document.createElement("table"); 
table.border = 1; 
table.className = "tabley"; 
range.insertNode(table); 
+1

也許這有助於:http://stackoverflow.com/q/9083705/778118 – jahroy 2013-02-13 23:21:02

+1

...或者這個:http://stackoverflow.com/q/5421892/778118 – jahroy 2013-02-13 23:21:32

回答

0

document.selection.createRange之前();是在IE中創建一個範圍對象的代碼,並且相當於在IE中使用的getRangeAt方法> = 9

+0

這通常會創建一個'TextRange',它爲DOM Range提供類似的用途,但有一個非常不同的API,所以它們不是真的等效。 – 2013-07-04 12:04:49

相關問題