2011-08-24 33 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',但它不起作用。 –

相关问题