capture click event of submit button jquery

后端 未结 6 1805

I am trying to get the click event of a submit button on my form...



        
相关标签:
6条回答
  • 2021-02-06 00:48

    You might haven't included the jquery library in your code!

    src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    0 讨论(0)
  • 2021-02-06 00:51
    $('#submitDemo').click(function() {
      // do your stuff
    });
    
    0 讨论(0)
  • 2021-02-06 00:53

    For form you can also bind submit button click on form.

    $("#form_selector").submit(function{
    // Do your stuff
    })
    

    where 'form_selector' is id of the form of which submit button is clicked.

    0 讨论(0)
  • 2021-02-06 00:54

    You need to run your script when the DOM is ready, as well as providing a callback to the click method:

    $(function() {
        $('#submitDemo').click(function() {
            // do your stuff
        });
    });
    
    0 讨论(0)
  • 2021-02-06 00:58

    try this

    $('#submitDemo').live("click",function() {
      // your stuff
    });
    

    As @px5x2 pointed that live is deprecate so instead of live use ON

    $('#submitDemo').on("click",function() {
      // your stuff
    }); 
    
    0 讨论(0)
  • 2021-02-06 01:00

    You have to encase your code in a function..

    $('#submitDemo').click(function(){
        alert("work darn it!!!!!!!!!!!!!!!!!!!!!!!!!")
        //$("#list").block({ message: '<img src="../../Images/ajax-loader.gif" />' })
    });
    

    But it is always a good practice to bind the event using on so that it attaches the event handler to the element when that is available.. So

    $('#submitDemo').on('click',function(){
        alert("work darn it!!!!!!!!!!!!!!!!!!!!!!!!!")
        //$("#list").block({ message: '<img src="../../Images/ajax-loader.gif" />' })
    });
    
    0 讨论(0)
提交回复
热议问题