如何在jquery中将文本框值与单个循环中的其他文本框进行比较 [英] How to compare a textbox value with other textboxes in a single loop in jquery
本文介绍了如何在jquery中将文本框值与单个循环中的其他文本框进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有10个文本框,我需要使用jquery将每个Textbox值与所有其他文本框进行比较,请帮我拿样例。
Hi
I have 10 Textboxes, I need to compare each Textbox value with all other Textboxes using jquery, please help me out with sample example.
var ids = $('input[id*="txtDate"]');
var i = 0;
for (i = 0; i < ids.length; i++) {
// //debugger;
if (ids[i].type == 'text')
{
if (ids[i].value == ids[i+1].value)
alert("plz select other date");
return false;
}
}
我正在尝试使用上面提到的代码,但循环不能正常工作
I am trying to use the above code which i have mentioned, but the loop is not working properly
推荐答案
(' input [id * =txtDate]');
var i = 0 ;
for (i = 0 ; i< ids.length; i ++){
// // debugger;
if (ids [i] .type == ' text')
{
if (ids [i] .value == ids [i +1] .value)
alert( plz select other date);
return false ;
}
}
('input[id*="txtDate"]'); var i = 0; for (i = 0; i < ids.length; i++) { // //debugger; if (ids[i].type == 'text') { if (ids[i].value == ids[i+1].value) alert("plz select other date"); return false; } }
我正在尝试使用上面提到的代码,但循环不能正常工作
I am trying to use the above code which i have mentioned, but the loop is not working properly
一些变化到你的代码 -
Some changes to your code -
var ids =
(< span class =code-string>' input [id * =txtDate]');
var i = 0 ,j = 0 跨度>;
for (i = 0 ; i< ids.length - 1 ; i ++){
// // debugger;
if (ids [i] .type == ' text')
{
for (j = i + 1; j< ids.length; j ++){
if (ids [i] .value == ids [j] .value){
alert( plz选择其他日期);
ids [j] .focus();
return false ;
}
}
}
}
('input[id*="txtDate"]'); var i = 0, j = 0; for (i = 0; i < ids.length - 1; i++) { // //debugger; if (ids[i].type == 'text') { for (j = i+1; j < ids.length; j++) { if (ids[i].value == ids[j].value) { alert("plz select other date"); ids[j].focus(); return false; } } } }
希望它可以帮助你...
问候,
Niral Soni
Hope it helps you out...
Regards,
Niral Soni
这篇关于如何在jquery中将文本框值与单个循环中的其他文本框进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文