2011-08-24 77 views
1

下面是一個關於IE的HTML編輯器的代碼部分:如何在IE瀏覽器HTML編輯器中觸發選擇事件?

var selectStr = []; 
selectStr.push("img[control_type='video']"); 
$(selectStr[0], document).selectionchange(function() { 
    alert(); 
}); // Explorer error: does not support this method or object. 
    // It seems JQuery does not support 'selectionchange' event. 


document.onselectionchange = function(){ 
    alert(); 
} // this works for all elements in the editor. 

是否可以只適用於一個特定的元素?我tryied:

$(selectStr[0], document).onselectionchange = function(){ 
    alert(); 
} // does not fire when selected. 

alert($(selectStr[0], document)); // [object, object] 

如果$(selectStr[0], document)改爲SOMETHING,這樣它會提醒[object, HTMLImgElement],這個問題將得到解決。任何人都知道如何以正確的方式做到這一點?

+0

答案是'$(「img [control_type ='video']」,document)[0]'。多謝你們! –

回答

0

這位朋友你好,你必須使用事件「焦點的時候」在Internet Explorer的事件,併爲Firefox u必須使用「ondragstart」事件,查找選擇事件。

希望這可以幫助你。

+0

document.onselectionchange = function(){ alert(); } //這適用於編輯器中的所有元素。 –

+0

嗯好吧然後繼續 – AmGates

+0

它可以只適用於特定的元素?我使用'$(selectStr [0],document)'替換'document',但它不起作用。 –