how to detect which button is clicked using jQuery

前端 未结 4 1114
青春惊慌失措
青春惊慌失措 2020-12-17 10:46

how to detect which button is clicked using jQuery

4条回答
  •  忘掉有多难
    2020-12-17 11:20

    jQuery can be bound to an individual input/button, or to all of the buttons in your form. Once a button is clicked, it will return the object of that button clicked. From there you can check attributes such as value...

    $('#dCalc input[type="button"]').click(function(e) {
        // 'this' Returns the button clicked:
        // 
        // You can bling this to get the jQuery object of the button clicked
        // e.g.: $(this).attr('id'); to get the ID: #btn1
        console.log(this);
    
        // Returns the click event object of the button clicked.
        console.log(e);
    });
    

提交回复
热议问题