Jquery - How to trigger $('#myForm').submit(function()

后端 未结 6 1778
暗喜
暗喜 2020-12-30 02:56

how can i trigger this function without using the form submit?

$(\'#myForm\').submit(function()
{ ....
6条回答
  •  遥遥无期
    2020-12-30 03:20

    You will have to dig it from DOM data. But, let me tell you, its not recommended. Try this,

    var form = $('#myForm');
    var data = form.data();
    var events = data.events;
    

    If the handler function is attached to form 'submit', it will be present as,

    var submit_list = events.submit;
    

    Now, if all goes well, at best you can get submit_list as list of all the handler objects attached to submit event of form.

    Shortcut: Assuming you have one and only one handler attached to submit event for #myForm,

    $('#myForm').data().events.submit[0].handler
    

    is your function.

    Play with data(), but remember its not recommended. Happy Coding.

提交回复
热议问题