Is there a way to change event parameters in jQuery?

五迷三道 提交于 2019-11-29 07:55:07

You can't set the properties here no...because it's a different event object in the stop method. You can set some variables at a higher scope (like this), but none that will persist on the event object. It's not that it's "clearing" them really, it's just a brand spanking new object.


To make the selectable behave as if Ctrl is held down, bind to the mousedown event it uses ahead of time and set the .metaKey property on that event to true, like this:

$("#selectable").bind("mousedown", function(e) {
    e.metaKey = true;
}).selectable();

You can test it out here, remember to find before calling .selectable(), since event handlers are executed in the order bound.

I've updated the code. Have a look at this URL.

http://jsfiddle.net/phoenix_suresh/7f6j5/

Meanwhile, I've added ID attribute to

  • items so that you can have more control on it.
  • After finding this answer I noticed that you can use the originalEvent property on the event object returned in the selectable start event handler to set the ctrlKey property to true.

    Like so:

    $("#selectable").selectable({
        start: function (event, ui) {
            event.originalEvent.ctrlKey = true;
        }
    });
    

    Working fiddle

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