我正在尝试通过复选框提交带有malsup表单插件的表单,但我无法这样做,我发现了类似的内容,表示要执行以下操作,但我无法通过该选项。有没有人做过类似的事情?
//Check SMS Credits
var checksmscredits = {
target: '#responsecredits',
beforeSubmit: showRequest,
url: 'exec.php?action=checksmscredits',
success: function() {
jQuery('.loaders').hide();
}
};
jQuery('#checksmscredits').ajaxForm(checksmscredits);
<form id="checksmscredits" method="post" action=""><p><span class="pagedesc"><input type="checkbox" name="sms" onclick="submit()" value="1" /> Text Your Message<br /></span></p></form><div id="responsecredits"></div>
这是我在以下链接中找到的内容 submit form using ajaxform on checkbox click
$('form.date-response input[type=checkbox]').live('click', function(){
$(this).parent('form').ajaxForm().submit();
});
答案 0 :(得分:0)
使用提供的代码段,这是一个建议:
<script type="text/javascript">
$(document).ready(function()
{
var options = {
data: $('#checksmscredits').serialize(),
success: function(data)
{
showSuccess();
},
error: function()
{
showError();
}
};
$('#checksmscredits').ajaxForm(options);
});
function showSuccess(){
alert('Success!');
}
function showError(){
alert('Error!');
}
</script>
<form id="checksmscredits" method="post" action="">
<p><span class="pagedesc">
<input type="checkbox" name="sms" onclick="document.getElementById('checksmscredits').submit();" value="1" />
Text Your Message<br />
</span></p>
</form>
<div id="responsecredits"></div>