注意: 如果要禁止显示消息,请在errorPlacement函数中使用return false.不要将函数留空,因为这是草率的编码.errorPlacement: function (error, element) { return false;}, 此外,使用最新版本的插件文件,因为这将确保require_from_group方法运行无错误. 当您完全禁止显示这些消息时,我不明白您为什么使用messages选项.在这种情况下,您可以安全地删除messages.I have following input elements on my form and and validation form with jQuery validation plugin.HTML:<form name='frmUsers' id='frmUsers' method='post' action='#'> <div> <input type='text' name='name' id='name' placeholder='Name' /> </div> <br /> <div> <input type='text' name='fixed_budget' id='fixed_budget' placeholder='Fixed budget' /> </div> <br /> <div> <select name='budget' id='budget'> <option value=''>Select your budget</option> <option value='1000'>1000</option> <option value='2000'>2000</option> <option value='3000'>3000</option> <option value='4000'>4000</option> </select> </div> <br/> <div> <input id='save' type='submit' value='Save' /> </div></form>jQuery validation:$(document).ready(function () { $("#frmUsers").validate({ onkeyup: false, onfocusout: false, ignore: [], rules: { "name": { required: true }, "fixed_budget": { required: true }, "budget": { required: true } }, messages: { "name": { required: 'required' }, "first_name": { required: 'required' }, "last_name": { required: 'required' } }, errorPlacement: function (error, element) { }, submitHandler: function () { return false; } });});Now all elements are required fields but I have specific condition on Fixed budget (text box) and budget (select box).For example:When user click on submit, fixed budget and budget elements display with errors but (1) when user select any option on budget, set fixed budget field to not required. (2) when user input something on fixed budget set budget field to not required.Here is my working JSFiddle: http://jsfiddle.net/mananpatel/85KR4/384/Any Idea?Thanks. 解决方案 In other words, you only require one of those two fields filled out.Include the additional-methods.js file and use the require_from_group method.rules: { name: { required: true }, fixed_budget: { require_from_group: [1, ".requiredGroup"] }, budget: { require_from_group: [1, ".requiredGroup"] }},DEMO: http://jsfiddle.net/7om97gk8/Note:Use return false within the errorPlacement function if you want to suppress messages. Don't leave the function empty, as that's sloppy coding.errorPlacement: function (error, element) { return false;},Also, use the latest version of the plugin file as this will ensure the require_from_group method operates bug-free.I don't understand why you are using the messages option when you've totally disabled these messages from displaying. You can safely remove messages in this case. 这篇关于基于元素选择的jQuery验证条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-30 22:53