开发者

JQuery / JavaScript - trigger button click from another button click event

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(){
   开发者_StackOverflow// 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()


Well, you just fire the desired click event:

$(".first").click(function(){
    $(".second").click(); 
    return false;
});


jQuery("input.first").click(function(){
   jQuery("input.second").trigger("click");
   return false;
});


You mean this:

jQuery("input.first").click(function(){
   jQuery("input.second").trigger('click');
   return false;
});


By using JavaScript: document.getElementById("myBtn").click();


this works fine, but file name does not display anymore.

$(document).ready(function(){ $("img.attach2").click(function(){ $("input.attach1").click(); return false; }); });


If it does not work by using the click() method like suggested in the accepted answer, then you can try this:

//trigger second button
$("#second").mousedown();
$("#second").mouseup();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜