开发者

Submit button and jQuery

I was told by someone on this site that it 开发者_JAVA百科was best not to write inline function calls in your HTML when doing jQuery. It sounds like a good plan.

So using jQuery, how do I call a function upon a button submission?


You mean form submission. And you can do it by binding an onsubmit event handler to your form:

$("#myForm").submit(function() {
    // do something
});


Based on your question, there are 2 different events you might want to use.

If you want to capture the button click, then you want the "click" event of the button

If you want the form submit, then you want "submit" event of the form.


$('form[name=myForm]').submit(function(){

// function here

});

jQuery docs on submit();


Others already answered on how to do a form submission, but if you mean you just want to click the button then you would want to use

$('input[name=myButton]').click()

jQuery docs on click();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜