有没有办法在jQuery中更改事件参数? [英] Is there a way to change event parameters in jQuery?

查看:203
本文介绍了有没有办法在jQuery中更改事件参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将传入参数的参数更改为可选择的开始事件,所以我基本上可以允许我的用户使用可选的jQuery UI效果,而无需按住CTRL键。

I want to be able to change the parameters that are being passed into the selectable's start event, so I can basically allow my user to use the selectable jQuery UI effect without having to hold down the CTRL key.

JS

$(function() {
$( "#selectable" ).bind("mousedown", function(event, ui) {
    var result = $( "#select-result" ).empty();
    event.metaKey = event.ctrlKey = true;
});
$( "#selectable" ).selectable();
});

我有一个小提琴,我想在这里完成什么:

I have a fiddle with what I'm trying to accomplish here:

http://jsfiddle.net/josephbulger/ZfevM/

我遇到的问题是,当我在start方法中设置事件的参数时,stop方法没有看到我正在进行的更改。

The problem I'm having, is that when i set the event's parameters in the start method, the stop method is not seeing the changes I'm making.

有没有办法完成我想要做的事情?

Is there a way to accomplish what I'm trying to do?

推荐答案

您不能在此设置属性no ...因为它是 stop 不同 事件对象c $ c>方法。您可以在更高的范围内设置一些变量(像这样),但不会持续存在事件对象。这不是真的清除他们,只是一个打屁股的新对象。

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.

要使可选择的行为为如果 Ctrl 被关闭,绑定到它提前使用的 mousedown 事件并设置 .metaKey 属性,该 事件 true ,如下所示:

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

你可以在这里测试,记住在调用 .selectable()之前找到,因为事件处理程序是执行在订单绑定。

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

这篇关于有没有办法在jQuery中更改事件参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆