【问题标题】:how to fire selection event in a IE HTML editor?如何在 IE HTML 编辑器中触发选择事件?
【发布时间】:2011-08-24 11:05:29
【问题描述】:

这是来自 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. 

它只能应用于特定元素吗?我试过了:

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

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

如果将$(selectStr[0], document) 更改为SOMETHING 以提醒[object, HTMLImgElement],则问题将得到解决。谁知道如何以正确的方式做到这一点?

【问题讨论】:

  • 答案是$("img[control_type='video']", document)[0]。谢谢,伙计们!

标签: javascript jquery editor


【解决方案1】:

您好朋友,您必须在 Internet Explorer 中使用“onselectstart”事件,而对于 Firefox,您必须使用“ondragstart”事件来查找选择事件。

希望对你有所帮助。

【讨论】:

  • document.onselectionchange = function(){ alert(); } // 这适用于编辑器中的所有元素。
  • 它只能应用于特定元素吗?我用$(selectStr[0], document)代替document,但是不行。
  • 我想是的。它可以应用于特定元素。尝试将图像放在 div 中并将事件应用于 div。
  • ondragstart 不会帮助您通过键盘或使用上下文和编辑菜单中的“全选”选项进行选择。
猜你喜欢
  • 2020-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-09
  • 2023-03-30
相关资源
最近更新 更多