2011-01-13 69 views
0

我有JQuery表单插件,但我没有提交表单中的按钮?我有一个复选框,点击我提交表单。表单被提交但没有ajax。我很喜欢是否可以使用jQuery表单插件而不用提交按钮。 ?jquery表单插件问题

这是我用于使用复选框onlclick事件提交jquery表单插件的代码。没有onclick事件,任何事情都可以正常工作。

$('#anl_popup').hide(); 
var options = { success: showResponse // post-submit callback }; 

$('#favourite_form').submit(function() { 
    $(this).ajaxSubmit(options); 
    return false; 
}); 

$('#remember_checkbox').click(function() { 
    document.favourite_form.submit(); 
    return false; 
}); 
+1

是的,它并不在乎你有没有按钮。也许你应该把你的代码放在这里让我们知道它有什么问题。 – xandy 2011-01-13 00:46:50

回答

1

是的,你可以在没有提交按钮的情况下提交你的表单。 我会建议这样写:

$(function() { 
    $('#favourite_form').ajaxForm({ success: showResponse }); 
    $('#remember_checkbox').click(function() { 
     this.form.submit(); 
    }); 
}); 
function showResponse(responseText, statusText, xhr, $form) { 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
     '\n\nThe output div should have already been updated with the responseText.'); 
} 

这应该够了。