我想验证引导模式中的表单,但是当页面加载时插件中的validate函数没有找到因为它已经被Modal类隐藏了。我怎样才能验证形式,然后它与模态消失。 我已经尝试使用验证()当我点击我的行动打开模式,但我不断收到以下错误信息,当我尝试提交: TypeError:$元素[0]是undefined这里是代码(JS )我使用验证,当我点击“保存更改”按钮:什么是使用jquery插件验证器作为引导模式验证表单的正确方法
$('#SavePortInfo').click(function() {
$("#PortNumberForm").validate();
var ValidStatus = $("#PortNumberForm").valid();
if (ValidStatus == false) {
console.log('Form no GOOD');
}else
{
$("#PortNumberForm").submit();
}
});
这里是我的代码为我的模式
<div id="PortNumberModal" class="modal fade">
<div class="modal-dialog" style="width:60%">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h4 class="modal-title">Port Number Information</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="PortNumberForm" name="PortNumberForm">
<fieldset>
<!-- Form Name -->
<!-- Prepended checkbox -->
<div class="form-group">
<label class="col-md-4 control-label" for="VOIP-PORT-5">Acknowledge Disconnect of Previous Phone</label>
<div class="col-md-2">
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" class="required">
</span>
<input id="VOIP-PORT-5" name="VOIP-PORT-5" class="form-control required" placeholder="" type="text">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="VOIP-PORT-4B">CIty on Previous Phone Account</label>
<div class="col-md-4">
<input id="VOIP-PORT-4B" name="VOIP-PORT-4B" placeholder="CIty on Previous Phone Account" class="form-control input-md required" type="text">
<span class="help-block">Please enter the city from your current telephone account</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="VOIP-PORT-4A">The First Line of the Address on my Current Phone Account</label>
<div class="col-md-4">
<input id="VOIP-PORT-4A" name="VOIP-PORT-4A" placeholder="placeholder" class="form-control input-md required" required type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="VOIP-PORT-3">The Name on my Current Phone Account</label>
<div class="col-md-4">
<input id="VOIP-PORT-3" name="VOIP-PORT-3" placeholder="placeholder" class="form-control input-md required" required type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="VOIP-PORT-2">My Current Phone Number</label>
<div class="col-md-4">
<input id="VOIP-PORT-2" name="VOIP-PORT-2" placeholder="" class="form-control input-md required" required type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="VOIP-PORT-4-ZIP">The Zip Code of the Address on my Current Phone Account</label>
<div class="col-md-4">
<input id="VOIP-PORT-4-ZIP" name="VOIP-PORT-4-ZIP" placeholder="" class="form-control input-md required" required type="text">
</div>
</div>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="SavePortInfo">Save changes</button>
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
任何帮助是appreciated.thank你。
实际上,插件只强制使用'name'属性。缺少'id'对jQuery Validate没有任何影响。 – Sparky 2015-03-14 05:12:25