如果我在HTML文檔中有兩個節點,那麼如何判斷使用DOM方法的Javascript文檔中,哪一個以HTML文檔順序排在第一位?確定來自節點的文檔順序
例如,
function funstuff(a, b) {
//a and b can be any node in the DOM (text, element, etc)
if(b comes before a in document order) {
var t = b; b = a; a = t;
}
// process the nodes between a and b. I can handle this part
// when I know that a comes before b.
}
應該指出,Resig的方法只能在元素節點上工作,而不能在文本節點上工作。 – Michael 2009-09-16 19:33:29
是的。文本節點沒有.sourceIndex,並且沒有.contains()。 – Michael 2009-09-17 18:35:54
&&在所有這些情況下都不會做任何事情,因爲RHS總是如此。 – gsnedders 2011-04-12 11:43:41