Ale*_*lex 37 html javascript jquery input
我有这个HTML,看起来像这样:
<input type="submit" name="savebutton" class="first button" />
<input type="submit" name="savebutton" class="second button" />
Run Code Online (Sandbox Code Playgroud)
和JS:
jQuery("input.second").click(function(){
// trigger second button ?
return false;
});
Run Code Online (Sandbox Code Playgroud)
那么如何通过点击第一个按钮从第二个按钮触发click事件呢?请注意,我没有对第二个按钮的任何控制,也没有对html或其上的点击事件的控制......
小智 26
好吧,你只需触发所需的点击事件:
$(".first").click(function(){
$(".second").click();
return false;
});
Run Code Online (Sandbox Code Playgroud)
小智 16
jQuery("input.first").click(function(){
jQuery("input.second").trigger("click");
return false;
});
Run Code Online (Sandbox Code Playgroud)
你是这个意思:
jQuery("input.first").click(function(){
jQuery("input.second").trigger('click');
return false;
});
Run Code Online (Sandbox Code Playgroud)