我有一些输入元素分组在不同的 div 中,我需要确保同一组中的输入不具有相同的值。
示例:
<div class="group1">
<input name="group1a" id="group1a"/>
<input name="group1b" id="group1b"/>
<input name="group1c" id="group1c"/>
<input name="group1d" id="group1d"/>
<div>
<div class="group2">
<input name="group2a" id="group2a"/>
<input name="group2b" id="group2b"/>
<input name="group2c" id="group2c"/>
<input name="group2d" id="group2d"/>
<div>
所有这些输入都有一些值(用户输入的),因此我想检查用户是否在group1的任何输入中输入相同值(与相同) group2,group3,...)然后系统将警告用户“您不能在该组中输入任何相同的值”
使用 jQuery 最有效的方法是什么?
最佳答案
你可以这样做:
$('input').blur(function(){
var curr = this.value;
if(curr != '' && $(this).siblings('input[value='+curr+']').length > 0){
alert('you can\'t enter the same value twice in the same group');
this.value = '';
}
});
关于jquery - 如何检查多个输入组中是否重复出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9483178/