列表框上的双击事件不能在IE中触发 [英] Double click event on option of listbox not firing in IE
问题描述
我想在列表框中的选项标签附加一个事件,以便当我点击其中一个时,它会移动到另一个列表框。
I want to attach an event to the option tags in a list box so that when I click one of them, it moves to another list box.
我有这个代码:
$('#' + opts.leftListId + ' > option').live('dblclick', function () {
// Move the object
});
在Firefox中工作正常,但在IE中,事件根本没有被触发。我不能使用双击选择节点,因为我只需要移动被点击的。
任何想法?
Works fine in Firefox, but in IE the event is not fired at all. I can't use double click on the select node, because I need to move only the one that was clicked on. Any ideas?
推荐答案
请改为:
$('#' + opts.leftListId).find('option').each(function(){
$(this).live('dblclick', function () {
// Move the object
});
});
更新(10:21 GMT)
Update (10:21 GMT)
尝试取消直播:
$('#' + opts.leftListId).find('option').each(function(){
$(this).dblclick( function () {
// Move the object
});
});
看到这个例子 - http://jsfiddle.net/hr7Gd/
See this example - http://jsfiddle.net/hr7Gd/
更新(10:45 GMT)
Update (10:45 GMT)
您的其他选项是在select(可以工作!)上运行 dblclick()
已经选择了这个选项的vale,并且使用它:
Your other option is to run the dblclick()
on the select (which works!) and the get the vale of wich option has been selected and work with that:
$("select").dblclick(function () {
var str = "";
$("select option:selected").each(function () {
str += $(this).text() + " ";
});
$("span").text(str);
})
.trigger('change');
看到这个例子在这里工作 - http://jsfiddle.net/hr7Gd/1/
See this example working here - http://jsfiddle.net/hr7Gd/1/
这篇关于列表框上的双击事件不能在IE中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!