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

前端 未结 7 1533
长发绾君心
长发绾君心 2020-12-13 06:10

I have this HTML which looks like this:




        
相关标签:
7条回答
  • 2020-12-13 06:30

    You mean this:

    jQuery("input.first").click(function(){
       jQuery("input.second").trigger('click');
       return false;
    });
    
    0 讨论(0)
  • 2020-12-13 06:38

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

    //trigger second button
    $("#second").click()
    
    0 讨论(0)
  • 2020-12-13 06:39
    jQuery("input.first").click(function(){
       jQuery("input.second").trigger("click");
       return false;
    });
    
    0 讨论(0)
  • 2020-12-13 06:44

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

    $(document).ready(function(){ $("img.attach2").click(function(){ $("input.attach1").click(); return false; }); });
    
    0 讨论(0)
  • 2020-12-13 06:47

    Well, you just fire the desired click event:

    $(".first").click(function(){
        $(".second").click(); 
        return false;
    });
    
    0 讨论(0)
  • 2020-12-13 06:48

    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 讨论(0)
提交回复
热议问题