Javascript 单击以触发要发生的事件(jQuery)

Javascript 单击以触发要发生的事件(jQuery),javascript,jquery,Javascript,Jquery,所以我有以下js代码: jQuery('.first_button').click(function(e) { var get_the_id= jQuery(this).data("custom_id"); var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false; if(!isMobile) {

所以我有以下js代码:

jQuery('.first_button').click(function(e) {         
    var get_the_id= jQuery(this).data("custom_id"); 
    var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
        if(!isMobile) {
            // if it is not mobile, the first click needs to trigger this function
            jQuery('.second_button_' + get_the_id).custom_plugin();                                     
        }else{
        //something else
        }   
})  
在这里,当单击第一个按钮时,它将获取自定义id作为变量,并查找第二个按钮“获取id”类。问题在于,第一次单击不会触发主功能(“自定义插件”),需要第二次单击


如何编辑它以使第一次单击触发功能(因此只需单击一次)?

是否在第一次单击时正确设置了
isMobile
?你确定问题出在这段代码上,而不是在初始化
custom_plugin()
?嗯,在代码前面有
isMobile
变量,我省略了
“}否则{”
。我将更新问题以获得澄清。如果
isMobile=false
custom_plugin
在第一次调用时起作用,则只需单击一次就可以了。奇怪的是,它需要第二次单击。下面是jsfiddle:如果您查看最后一个按钮(js的最后一部分),它将显示它需要两次单击。此外,第一次单击保存属性(例如,
data-custom\u id
)并查找特定按钮。我从插件作者()那里得到了解释,但很难弄清楚。