zoukankan      html  css  js  c++  java
  • 有关于5个文本栏

     

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

    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>

  • 相关阅读:
    C++小记
    滑窗问题总结
    leetcode 350 easy
    C++中的 istringstream 的用法
    leetcode 235-290 easy
    leetcode 198-234 easy
    CNN 常用的几个模型
    leetcode 60-80 easy
    python 正则的使用例子和goupby
    leetcode 31-40 easy
  • 原文地址:https://www.cnblogs.com/RuiLei/p/414842.html
Copyright © 2011-2022 走看看