发送数据到绑定函数。具有结构“click: function () {...}”
我可以发送这样的数据(数据不同)?
$("div.test").bind("click", {foo: "bar1"}, function(event) { ... })
$("div.test").bind("mouseenter", {foo: "bar2"}, function(event) { ... })
$("div.test").bind("mouseleave", {foo: "bar3"}, function(event) { ... })
但使用这种结构:
$("div.test").bind({
click: function(){ ... },
mouseenter: function(){ ... },
mouseleave: function(){ ... }
});
是否也可以发送相同的信息,“但不是在用数据声明变量之前:
不是这个:
var data = "test";
$("div.test").bind({
click: function(){
// use data
},
mouseenter:{
// use data
},
mouseleave: {
// use data
}
});
谢谢
I can send data such as this (the data are different)?
$("div.test").bind("click", {foo: "bar1"}, function(event) { ... })
$("div.test").bind("mouseenter", {foo: "bar2"}, function(event) { ... })
$("div.test").bind("mouseleave", {foo: "bar3"}, function(event) { ... })
but with this structure:
$("div.test").bind({
click: function(){ ... },
mouseenter: function(){ ... },
mouseleave: function(){ ... }
});
and is it also possible to send the same information, "but not before declaring a variable with the data:
not this:
var data = "test";
$("div.test").bind({
click: function(){
// use data
},
mouseenter:{
// use data
},
mouseleave: {
// use data
}
});
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定为什么它很重要,但如果您只是不想让它再次运行选择器,您可以做两件事:
1)在绑定之前保存对象:
2)您可以链接它们:
您想这样做还有其他原因吗?
编辑
为了明确回答这个问题,不,如果不使用 jQuery“map”对象格式在外部声明数据,就不可能传递数据。除非您手动触发事件,我认为这不是您想要做的。
I'm not sure why it matters, but if you just don't want it running the selector over again, you can do two things:
1) Save the object before binding:
2) You could chain them:
Is there another reason why you want to do this?
Edit
To explicitly answer the question, no it's not possible to pass data in without declaring it outside with the jQuery "map" object format. Unless you trigger the events manually, which I don't think is what you want to do.
好吧,不是我想要的,但它对我有用:
HTML
JS
example
well, not what I wanted but it is useful to me:
HTML
JS
example