[英]How to Check if Multi Inputs have same Value with same Classes (jQuery)
I want to apply validation in input to no to add the same value again. 我想在输入中将验证应用于否,以再次添加相同的值。
<input type="text" data-loop="1" class="form-control Item_1 Item" name="Item">
<input type="text" data-loop="1" class="form-control Item_2 Item" name="Item">
<input type="text" data-loop="1" class="form-control Item_3 Item" name="Item">
Here is the jQuery to handle this. 这是处理此问题的jQuery。
$('.TableBody').on('change', '.Item', function() {
var loop_id = $(this).data('loop');
var Item = $('.Item_'+loop_id).closest('.Item').val();
});
});
Any help would be highly appreciated. 任何帮助将不胜感激。
Loop over the input files and use the values as keys: 循环输入文件并将这些值用作键:
(Pseudo code) (伪代码)
lookup = {}
for each([item_number, value])) {
if (lookup[value]) {
throw error ('Items ' + item_number + ' and ' + lookup[value] + ' are identical')
} else {
lookup[value] = item_number
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.