我想为我的应用程序中的所有表单提交事件编写一个 js/jquery 函数。
目前我正在在 3 个位置这样进行硬编码,并且它正在工作,但我必须分别为每个表单创建一个函数:
jQuery('#myForm').live('submit',function(event) { // #myForm hardcoded here
$.ajax({
url: 'one.php', // one.php hardcoded here
type: 'POST',
data: $('#myForm').serialize(), // #myForm hardcoded here
success: function( data ) {
alert(data);
}
});
return false;
});
谢谢
最佳答案
jQuery('form').live('submit',function(event) {
$.ajax({
url: $(this).attr('action'),
type: 'POST',
data: $(this).serialize(),
success: function( data ) {
alert(data);
}
});
return false;
});
关于php - 如何为所有表单提交事件编写通用 js 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3586610/