我试图在提交表单时调用函数,此函数应该适用于所有带有div"#js_ajax_form"的表单。 (javascript代码适用于chrome控制台 // html代码
<form method="post" id="js_ajax_form" data-type="user.registration" action="signup">
<input type="text" name="val[first_name]" id="first_name" placeholder="First Name" value="" size="30">
<input type="text" name="val[last_name]" id="last_name" placeholder="Last Name" value="" size="30">
<input type="submit" value="Sign Up" class="button_register" id="js_registration_submit">
</form>
// javascript
var $Core = {};
function getParam(sParam)
{
return oParams[sParam];
}
$Core.form = function()
{
$("#js_ajax_form").submit(function(e)
{
var postData = $(this).serializeArray();
alert(postData);
e.preventDefault(); //STOP default action
e.unbind(); //unbind. to stop multiple form submit.
});
}
答案 0 :(得分:-1)
只要您使用jQuery,以下代码就可以运行:
$("#myform").submit(function() {
myFunction();
// the form will continue on submission
});