How to Handle Button Click Events in jQuery?

前端 未结 9 1916
悲&欢浪女
悲&欢浪女 2020-12-04 08:04

I need to have a button and handle its event in jQuery. And I am writing this code but it\'snot working. Did I miss something?

  
         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 08:42

    $('#btnSubmit').click(function(){
        alert("button");
    });
    

    or

    //Use this code if button is appended in the DOM
    $(document).on('click','#btnSubmit',function(){
        alert("button");
    });
    

    See documentation for more information:
    https://api.jquery.com/click/

提交回复
热议问题