我正在尝试使用jQuery .submit()方法提交表单。它适用于所有浏览器,但IE8标准模式,当然这是我必须支持的浏览器。这是我的代码:
$("button.submit").on('click', function (){
if($(this).hasClass('disabled'))
{
$("div.alerts").html("<h3 class='error'>You do not have sufficient permissions for this action</h3>").fadeIn().delay(2000).fadeOut();
return false;
}
var passed = true;
$('.required').each(function(){
console.log('validating required elements');
if(!$(this).val() || $(this).val() == 0 || $(this).val() == '')
{
$("div.alerts").html("<h3 class='error'>Required Information is missing. Please enter the " + $(this).attr('name') + " field").fadeIn().delay(2000).fadeOut();
$(this).on('keyup click', function(){$(this).css('background-color', '#fff');});
$(this).css('background-color', 'red').focus();
passed = false;
return false;
}
});
if(passed)
{
console.log('saving');
$("form#editTemplate").submit();
}
以下是表格:
<form id = 'edittemplate' ENCTYPE="multipart/form-data" method = "POST" action ="somefile.php" >
<ul>
<span class='left'>
<li>
<label>Title</label>
<span class='formElement'><input type='text' name='name' class='required' value = 'example'/></span>
</li>
<li>
<label>Description</label>
<span class='formElement'><input type='text' name='description' class='required' value = 'example' /></span>
</li>
<li>
<label>Subject</label>
<span class='formElement'><input type='text' class='required' name='templatesubject' value = 'example'/></span>
</li>
<li>
<label>CID</label>
<span class='formElement'><input type='text' name='c2ktemplateid' value = '509' readonly="readonly"/></span>
</li>
<li>
<label>Attachments</label>
<span class='formElement'><input type='file' name='attachment' id='attachment' /></span>
</li>
</span>
</ul>
</form>
我在页面上有多个隐藏的表单(对于jquery模式表单)。我知道输入按钮不起作用,但你甚至无法点击提交。此外,如果我观看控制台,它确实可以“保存”提交事件,但不会触发。谢谢你的帮助。