在这里我的要求是,一旦我们在一个选择框中选择SON或父亲,如果我在另一个选择框中选择"婆婆"或"父亲在法律",我想要一条警告信息,例如"公婆不适用".
这是我的代码,
if (arr.indexOf(!(($(this).val() == 'Son' || $(this).val() == 'Father'))) > -1) {
alert('In-laws are not applicable');
return false;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我.jsFiddle就在这里.
-谢谢.
您可以在用户选择或后检查每一个正在selects查找的或:SonFatherFather-in-lawMother-in-law
if($(this).val()=='Mother-in-law' || $(this).val()=='Father-in-law'){
//for each of the Relation selects, we check if anyone is Son or Father
$('.classSelect').each(function(){
var currentSelect = $(this).val();
if( currentSelect == 'Son' || currentSelect == 'Father'){
alert("In-laws are not applicable");
}
});
}
Run Code Online (Sandbox Code Playgroud)
活生生的例子: http: //jsfiddle.net/4QUMG/10/
使用数组的实例arr:http://jsfiddle.net/4QUMG/12/
$(this).val()另外,我会保存变量内部的值。