Double click event on option of listbox not firing in IE

浪尽此生 提交于 2019-12-05 07:15:46

Try this instead:

$('#' + opts.leftListId).find('option').each(function(){
  $(this).live('dblclick', function () {
     // Move the object
  });
});

Update (10:21 GMT)

Try taking out the live:

$('#' + opts.leftListId).find('option').each(function(){
  $(this).dblclick( function () {
     // Move the object
  });
});

See this example - http://jsfiddle.net/hr7Gd/

Update (10:45 GMT)

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');

See this example working here - http://jsfiddle.net/hr7Gd/1/

Doubleclick won't fire on ie if you try to add them to option elements, no matter how you add it. The only thing that I've got working in IE is to add the event watch to the select itself and then to look at selected elements:

$("select").dblclick(function () {
  $("select option:selected").each(function () {
    alert(this);
  });
});    

Got it - I was wrong thinking that I couldn't use the select's double click event.

This is the working code:

$('#' + opts.leftListId).dblclick(function () {
      // Move selected options: $('#' + opts.leftListId + ' :selected')
});

The reason I didnt think that this would work is that I thought it would move over all selected elements rather than just the one clicked on. However, it appears that the first click of a double-click selects only the one element, before this event fires on double click and moves it across.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!