如何在.click()函数中传递参数? [英] How can I pass arguments in .click() function?

查看:2074
本文介绍了如何在.click()函数中传递参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下情况下,我想将参数传递给click()处理函数:

I want to pass arguments to the click() handler function in the following case:

function edit_tab(val){
    var prev_tab = $("#current_tab").html();
    if (prev_tab == 1) {
        $('.edit-basic-info').click(a); // here I want to pass some argument "a".
    }
}

如何在上面的代码中传递参数a?我尝试做的方法不起作用.

How can I pass the argument a in the above code? The way I am trying to do is not working.

推荐答案

您可以使用trigger()'s extraParameters将其他参数传递给处理程序:

You can use trigger()'s extraParameters to pass additional parameters to your handler:

trigger() 文档中:

extraParameters类型:Array或PlainObject 传递给事件处理程序.

extraParameters Type: Array or PlainObject Additional parameters to pass along to the event handler.

示例(同样来自文档):

Example (also from the documentation):

$( "#foo" ).on( "custom", function( event, param1, param2 ) {
  alert( param1 + "\n" + param2 );
});

$( "#foo").trigger( "custom", [ "Custom", "Event" ] );

这篇关于如何在.click()函数中传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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