- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了一个问题,jQuery 验证插件 [ https://jqueryvalidation.org/ ] 没有触发我的表单提交。
脚本在 Lint 中检查没有语法错误。 Google Chrome 开发者控制台没有报告任何问题。
然而,表单只是提交而没有验证任何内容。
请参阅下面的代码片段。
$(document).ready(function () {
$('input[name=DonationType]:radio').on('change', function () {
if ($('#DonationTypeIndividual').is(':checked')) {
$('#CompanyName').prop( 'disabled', true );
}
else
{
$('#CompanyName').prop( 'disabled', false );
}
});
$('#InHonorOf').on('change', function () {
if ($('#InHonorOf').is(':checked')) {
$('#InHonorOfName').prop( 'disabled', false );
}
else {
$('#InHonorOfName').prop( 'disabled', true );
}
});
$('#InMemoryOf').on('change', function () {
if ($('#InMemoryOf').is(':checked')) {
$('#InMemoryOfName').prop( 'disabled', false );
}
else {
$('#InMemoryOfName').prop( 'disabled', true );
}
});
$('input[name=GiftNotificationMethod]:radio').on('change', function () {
if ($('#GiftNotificationMethodNone').is(':checked')) {
$('#GiftNotificationMessage').prop( 'disabled', true );
$('#GiftNotificationName').prop( 'disabled', true );
$('#GiftNotificationEmail').prop( 'disabled', true );
$('#GiftNotificationStreet01').prop( 'disabled', true );
$('#GiftNotificationStreet02').prop( 'disabled', true );
$('#GiftNotificationCity').prop( 'disabled', true );
$('#GiftNotificationState').prop( 'disabled', true );
$('#GiftNotificationZIPCode').prop( 'disabled', true );
}
else if ($('#GiftNotificationMethodEmail').is(':checked')) {
$('#GiftNotificationMessage').prop( 'disabled', false );
$('#GiftNotificationName').prop( 'disabled', false );
$('#GiftNotificationEmail').prop( 'disabled', false );
$('#GiftNotificationStreet01').prop( 'disabled', true );
$('#GiftNotificationStreet02').prop( 'disabled', true );
$('#GiftNotificationCity').prop( 'disabled', true );
$('#GiftNotificationState').prop( 'disabled', true );
$('#GiftNotificationZIPCode').prop( 'disabled', true );
}
else if ($('#GiftNotificationMethodMail').is(':checked')) {
$('#GiftNotificationMessage').prop( 'disabled', false );
$('#GiftNotificationName').prop( 'disabled', false );
$('#GiftNotificationEmail').prop( 'disabled', true );
$('#GiftNotificationStreet01').prop( 'disabled', false );
$('#GiftNotificationStreet02').prop( 'disabled', false );
$('#GiftNotificationCity').prop( 'disabled', false );
$('#GiftNotificationState').prop( 'disabled', false );
$('#GiftNotificationZIPCode').prop( 'disabled', false );
}
});
var registrationFormValidator = $('#DonationForm').validate({
errorElement: 'div',
rules: {
DonationAmount: { required: true },
FullName: { required: true },
Street01: { required: true },
City: { required: true },
ZIPCode: { required: true, zipcodeUS: true },
Email: { required: true, email: true },
Phone: { phoneUS: true },
Fax: { phoneUS: true },
InHonorOfName: { required: true },
InMemoryOfName: { required: true },
GiftNotificationName: { required: true },
GiftNotificationEmail: { required: true, email: true },
GiftNotificationStreet01: { required: true },
GiftNotificationCity: { required: true },
GiftNotificationZIPCode: { required: true, zipcodeUS: true },
CardNumber: { required: true },
CardExpiration: { required: true },
CardSecurityCode: { required: true, digits: true }
},
messages: {
DonationAmount: { required: $('#DonationAmount').data('validationRequired') },
FullName: { required: $('#FullName').data('validationRequired') },
Street01: { required: $('#Street01').data('validationRequired') },
City: { required: $('#City').data('validationRequired')},
ZIPCode: { required: $('#ZIPCode').data('validationRequired'), zipcodeUS: $('#ZIPCode').data('validationFormat') },
Email: { required: $('#Email').data('validationRequired'), email: $('#Email').data('validationFormat') },
Phone: { phoneUS: $('#Phone').data('validationFormat') },
Fax: { phoneUS: $('#Fax').data('validationFormat') },
InHonorOfName: { required: $('#InHonorOfName').data('validationRequired') },
InMemoryOfName: { required: $('#InMemoryOfName').data('validationRequired') },
GiftNotificationName: { required: $('#GiftNotificationName').data('validationRequired') },
GiftNotificationEmail: { required: $('#GiftNotificationEmail').data('validationRequired'), email: $('#GiftNotificationEmail').data('validationFormat') },
GiftNotificationStreet01: { required: $('#GiftNotificationStreet01').data('validationRequired') },
GiftNotificationCity: { required: $('#GiftNotificationCity').data('validationRequired')},
GiftNotificationZIPCode: { required: $('#GiftNotificationZIPCode').data('validationRequired'), zipcodeUS: $('#GiftNotificationZIPCode').data('validationFormat') },
CardNumber: { required: $('#CardNumber').data('validationRequired') },
CardExpiration: { required: $('#CardExpiration').data('validationRequired') },
CardSecurityCode: { required: $('#CardSecurityCode').data('validationRequired'), digits: $('#CardSecurityCode').data('validationFormat') }
},
errorPlacement: function (error, element) {
$(error).insertAfter($(element));
},
highlight: function (element, errorClass) {
$(element).parent('li').addClass('has-error');
},
unhighlight: function (element, errorClass, validClass) {
$(element).parent('li').removeClass('has-error');
},
onfocusout: false,
invalidHandler: function (event, validator) {
setTimeout(function () {
$('input:text').blur();
$('textarea').blur();
}, 10);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/additional-methods.min.js"></script>
<form method="post" id="DonationForm" action="/">
<div class="form-group">
<label for="DonationAmount" class="sr-only">Donation amount</label>
<div class="input-group">
<div class="input-group-addon">$</div>
<input type="number" class="form-control" id="DonationAmount" placeholder="Donation amount" data-validation-required="Please enter a valid donation amount.">
<div class="input-group-addon">.00</div>
</div>
</div>
<hr>
<div class="form-group">
<label for="FullName" class="sr-only">Your first and last name</label>
<div id="FullName">
<input type="text" class="form-control" id="FirstName" placeholder="First name" data-validation-required="Please enter your first name.">
<input type="text" class="form-control" id="LastName" placeholder="Last name" data-validation-required="Please enter your last name.">
</div>
</div>
<div class="form-group">
<label for="DonationType" class="sr-only">Donation Type</label>
<input type="radio" name="DonationType" id="DonationTypeIndividual" value="0" checked=""> Individual Donation<br>
<input type="radio" name="DonationType" id="DonationTypeCorporate" value="1"> Corporate Donation<br>
</div>
<div class="form-group">
<label for="CompanyName" class="sr-only">Company name</label>
<input disabled="" type="text" class="form-control" id="CompanyName" placeholder="Company name">
</div>
<div class="alert alert-warning" role="alert">
Please ensure that the address entered below matches the billing address for your credit card.
</div>
<div class="form-group">
<label for="Street01" class="sr-only">Street</label>
<input type="text" class="form-control" id="Street01" placeholder="Street address" data-validation-required="Please enter your street address.">
<input type="text" class="form-control" id="Street02" placeholder="">
</div>
<div class="form-group">
<label for="City" class="sr-only">City</label>
<input type="text" class="form-control" id="City" placeholder="City" data-validation-required="Please enter your city.">
</div>
<div class="form-group">
<label for="State" class="sr-only">State/Territory</label>
<select id="State" class="form-control">
<option>State/territory</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AS">American Samoa</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FM">Federated States Of Micronesia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="GU">Guam</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MH">Marshall Islands</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="MP">Northern Mariana Islands</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PW">Palau</option>
<option value="PA">Pennsylvania</option>
<option value="PR">Puerto Rico</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VI">Virgin Islands</option>
<option value="VA">Virgina</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="form-group">
<label for="ZIPCode" class="sr-only">ZIP Code</label>
<input type="text" class="form-control" id="ZIPCode" placeholder="ZIP Code" data-validation-required="Please enter your ZIP code." data-validation-format="Please enter a valid ZIP code.">
</div>
<div class="form-group">
<label for="Email" class="sr-only">Email</label>
<input type="email" class="form-control" id="Email" placeholder="Email address" data-validation-required="Please enter your email address.">
</div>
<div class="form-group">
<label for="Phone" class="sr-only">Phone</label>
<input type="tel" class="form-control" id="Phone" placeholder="Phone" data-validation-format="Please enter a valid phone number.">
</div>
<div class="form-group">
<label for="Fax" class="sr-only">Fax</label>
<input type="tel" class="form-control" id="Fax" placeholder="Fax" data-validation-format="Please enter a valid fax number.">
</div>
<hr>
<div class="form-group">
<input type="checkbox" id="InHonorOf">
<label for="InHonorOfName">In honor of</label>
<input disabled="" type="text" class="form-control" id="InHonorOfName" placeholder="In honor of..." data-validation-required="Please enter the name of the individual that you are giving this gift in honor of.">
</div>
<div class="form-group">
<input type="checkbox" id="InMemoryOf">
<label for="InMemoryOfName">In memory of</label>
<input disabled="" type="text" class="form-control" id="InMemoryOfName" placeholder="In memory of" data-validation-required="Please enter the name of the individual that you are giving this gift in memory of.">
</div>
<div class="form-group">
<label for="GiftNotification" class="sr-only">Gift Notification</label>
<input type="radio" name="GiftNotificationMethod" id="GiftNotificationMethodNone" value="0" checked=""> None<br>
<input type="radio" name="GiftNotificationMethod" id="GiftNotificationMethodEmail" value="1"> By Email<br>
<input type="radio" name="GiftNotificationMethod" id="GiftNotificationMethodMail" value="2"> By Mail<br>
</div>
<div class="form-group">
<label for="GiftNotificationMessage" class="sr-only">Message</label>
<textarea disabled="" class="form-control" id="GiftNotificationMessage" placeholder="Your message..." rows="4"></textarea>
</div>
<div class="form-group">
<label for="GiftNotificationName" class="sr-only">Recipient's Name</label>
<input disabled="" type="text" class="form-control" id="GiftNotificationName" placeholder="City" data-validation-required="Please enter your gift notification recipient's name.">
</div>
<div class="form-group">
<label for="GiftNotificationEmail" class="sr-only">Recipient's Email</label>
<input disabled="" type="email" class="form-control" id="GiftNotificationEmail" placeholder="Recipient's email address" data-validation-required="Please enter your gift notification recipient's email address." data-validation-format="Please enter a valid email address.">
</div>
<div class="form-group">
<label for="GiftNotificationStreet01" class="sr-only">Street</label>
<input disabled="" type="text" class="form-control" id="GiftNotificationStreet01" placeholder="Recipient's street address" data-validation-required="Please enter a street address for the gift notification.">
<input disabled="" type="text" class="form-control" id="GiftNotificationStreet02" placeholder="">
</div>
<div class="form-group">
<label for="GiftNotificationCity" class="sr-only">City</label>
<input disabled="" type="text" class="form-control" id="GiftNotificationCity" placeholder="Recipient's City" data-validation-required="Please enter a city for the gift notification.">
</div>
<div class="form-group">
<label for="GiftNotificationState" class="sr-only">State/Territory</label>
<select disabled="" id="GiftNotificationState" class="form-control">
<option>Recipient's state/territory</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AS">American Samoa</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FM">Federated States Of Micronesia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="GU">Guam</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MH">Marshall Islands</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="MP">Northern Mariana Islands</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PW">Palau</option>
<option value="PA">Pennsylvania</option>
<option value="PR">Puerto Rico</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VI">Virgin Islands</option>
<option value="VA">Virgina</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="form-group">
<label for="GiftNotificationZIPCode" class="sr-only">ZIP code</label>
<input disabled="" type="text" class="form-control" id="GiftNotificationZIPCode" placeholder="Recipient's ZIP code" data-validation-required="Please enter a ZIP code for the gift notification." data-validation-format="Please enter a valid ZIP code.">
</div>
<hr>
<div class="form-group">
<label for="CardNumber" class="sr-only">Card number</label>
<input type="number" class="form-control" id="CardNumber" placeholder="Card number" data-validation-required="Please enter a valid credit card number." maxlength="16">
<span>Numbers only, no spaces or dashes</span>
</div>
<div class="form-group">
<label for="CardExpirationDate" class="sr-only">Card expiration date</label>
<input type="text" class="form-control" id="CardExpirationDate" placeholder="Card expiration date" data-validation-required="Please enter your credit card's expiration date (MM/YY)." maxlength="5">
<span>MM/YY</span>
</div>
<div class="form-group">
<label for="CardSecurityCode" class="sr-only">Card security code</label>
<input type="text" class="form-control" id="CardSecurityCode" placeholder="Card security code" data-validation-required="Please enter your credit card's security code." data-validation-format="Please enter a valid credit card security code." maxlength="4">
<span><a href="javascript:var securityCodeWindow = window.open('https://account.authorize.net/help/Miscellaneous/Pop-up_Terms/Virtual_Terminal/Card_Code.htm', 'securityCode', 'width=480, height=480')">What's this?</a></span>
</div>
<div class="form-group">
</div>
<button type="submit" id="DonationFormSubmit" class="btn btn-primary">Send donation</button>
</form>
最佳答案
所有输入元素都没有 name
属性。考虑验证的每个元素必须包含唯一的名称
。
rules: {
DonationAmount: { // <- NAME attribute
required: true
},
FullName: { // <- NAME attribute
required: true
} ....
关于javascript - jQuery Validate 不会在提交时触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37428116/
当我尝试输入时,我正在关注 Ray Wenderlich ( https://videos.raywenderlich.com/screencasts/545-server-side-swift-wi
我正在使用 javax.validation.Validation 来验证 jpa 实体。我总是针对相同的实体进行验证。 我想知道是对所有验证使用一个 validator 更好,还是每次验证时实例化一
Controller : @RequestMapping(...) public void foo(@Valid Parent p){ } class Parent { @NotNull // j
在 login.phtml 中,validator 和 validate 之间有什么区别 - 有人可以解释下面每一行的含义 function onepageLogin(button)
我有一个 java bean 用于将 JSON 消息发送到 spring @RestController 并且我有 bean 验证设置并使用 @Valid 运行得很好。但我想转移到 Protobuf/
我正在使用 vee-validate 来验证注册表单,我编写了如下代码,
使用 有什么区别属性和 标签? 我应该什么时候使用哪一种? 最佳答案 validator属性允许您引用独立的托管 bean 方法,而不仅仅是像这样的验证器
我们有这个 Alamofire 错误处理: Alamofire.request(.GET, getUrl("mystuff")).responseData { response in guar
以下代码创建了两个单选按钮。每个选项都包含一个日期值,该日期值已成功转换为格式为“yyyy-MM-dd”的标签。一旦我做出选择并单击下一步按钮,我就会收到以下错误“j_idt12:comDateCho
是否有类似的验证: req.checkBody('property', 'should be present').isPresent(); 值本身并不重要。 现在我使用这个解决方案: .isLengt
系列文章: 1、async-validator 源码学习(一):文档翻译 2、async-validator 源码学习笔记(二):目录结构 3、async-validator 源码学习笔记(三):ru
我正在使用 Backbone.Validation插入。我有一个模型可以在服务器端进行唯一性检查。我如何让 backbone.validation 识别错误并运行我设置的回调以显示返回的错误消息? t
我有一个 Knockout.Validation 场景,我认为该场景相当普遍,但尚未通过在网络上搜索和本网站上的各种答案找到解决方案。 我正在验证的属性在 ajax 调用之后才会添加到可观察到的 kn
我是 Knockout JS 的新手。我需要一个验证器来验证用户将在文本框中输入的日期。为此编写了如下代码 ko.validation.rules['date'] = { validator:
如何在 JSF 验证器中比较两个字符串是否相等? if (!settingsBean.getNewPassword().equals(settingsBean.getConfirmPassword()
我有简单的域: package app class Customers { String CUSTOMER String NOTE static mapping = {
我正在使用 ember-validations 来验证表单中的模型。 如果我使用 createRecord 创建记录,则模型的实例已经过验证,因此在用户输入值之前表单已经显示验证错误。 我只想在提交表
我有两种不同的服务:第一个是将对象保存到数据库,第二个是更新现有对象。 我正在对我的对象使用验证约束,例如(@NotBlank、@Size、@Pattern 等),在第一种情况下,我需要验证对象的所有
我有 2 个 ensure - 验证装饰器用于 2 个字段:password 和 retypePassword。我想在填写 retypePassword 字段时检查这两个字段是否相等。 问题是,当我在
I'm aware that it's a bug ,但是在域类上调用 validate() 会覆盖之前放入的任何拒绝: def save = { def assignment = new A
我是一名优秀的程序员,十分优秀!