JQuery / JavaScript - 触发按钮单击另一个按钮单击事件 [英] JQuery / JavaScript - trigger button click from another button click event

查看:117
本文介绍了JQuery / JavaScript - 触发按钮单击另一个按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的HTML:

 < input type =submitname =savebuttonclass =第一个按钮/> 
< input type =submitname =savebuttonclass =second button/>

和JS:

  jQuery(input.second)。click(function(){
//触发第二个按钮?
返回false;
});

那么如何通过点击第一个按钮来触发点击事件?
请注意,我无法控制第二个按钮,无论是html还是点击事件...

解决方案添加id到两个输入,id =first和id =second

 //触发第二个按钮
$(#second)。click()


I have this HTML which looks like this:

<input type="submit" name="savebutton" class="first button" />
<input type="submit" name="savebutton" class="second button" />

and JS:

jQuery("input.second").click(function(){
   // trigger second button ?
   return false;
});

So how can I trigger the click event from the 2nd button by clicking on the first one? Note that I don't have any control over the 2nd button, neither on the html or the click event on it...

解决方案

Add id's to both inputs, id="first" and id="second"

//trigger second button
$("#second").click()

这篇关于JQuery / JavaScript - 触发按钮单击另一个按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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