现在的位置: 首页 > 综合 > 正文

有关于5个文本栏

2013年01月12日 ⁄ 综合 ⁄ 共 1203字 ⁄ 字号 评论关闭
 

下面有五个文本栏,我要做的工作就是检查五个文本栏中的值不能相同。

1[1] 2[1] 3[1] 4[1] 5[1]
1[2] 2[2]  3[2] 4[2] 5[2]



请问有没有好一点的比较法。

要求用JS编写。

我的检查方法是如下:

//12

if (1 == 2) {

  window.alert("12不能一样!!");

return false;

}

//13

if (1 == 3) {

 window.alert("13不能一样!!");

 return false;

}

//14

if (1 == 4) {

  window.alert("14不能一样!!");

return false;

}

//15

if (1 == 5) {

  window.alert("15不能一样!!");

return false;

}

//23

if (2 == 3) {

 window.alert("23不能一样!!");

 return false;

}

//24

if (2 == 4) {

  window.alert("24不能一样!!");

return false;

}

//25

if (2 == 5) {

 window.alert("25不能一样!!");

 return false;

}

//34

if (3 == 4) {

  window.alert("34不能一样!!");

return false;

}

//35

if (3 == 5) {

 window.alert("35不能一样!!");

 return false;

}

//45

if (4 == 5) {

 window.alert("45不能一样!!");

 return false;

}

====================================================
修正之后的算法
<html>
<script>
function a(){

   len = 5;
 
  for(i=0;i<len-1;i++){
     for(j=i+1;j<len;j++){
   first= eval("document.ff.t"+i);
  
  second = eval("document.ff.t"+j);
  
    if(first.value!=""&&second.value!=""&&second.value==first.value){
     k=i+1;h=j+1;alert("第"+k+"项不能和第"+h+"项相等")}
   }
  }
}
</script>
<body>
<form name="ff">
<input type="text" name="t0">
<input type="text" name="t1">
<input type="text" name="t2">
<input type="text" name="t3">
<input type="text" name="t4">
<input type="submit" onclick="a();">
</form>
</body>
</html>

抱歉!评论已关闭.