使用Javascript搜索号码

时间:2017-04-20 06:11:09

标签: javascript html typescript

我正在尝试使用typescript和javascript来查找数字,这是在用户提供的列表中。我想使用按钮' search'打印该号码是否在列表中。五个输入文本框和一个搜索文本框和搜索按钮。如果该号码列在任何用户输入文本框中>>打印为"是的,数字在列表中或提到框(最多五个框)"如果不是"对不起,您要搜索的号码不在列表中#34;



<html>
       <head>
       </head>
       <body>
                
          Enter a Number : <input type="text" name="textbox1" id="textbox1"  onkeyup="movetoNext(this, 'textbox2')" maxlength="2" /><br><br>
          Enter a Number : <input type="text" name="textbox2" id="textbox2"  onkeyup="movetoNext(this, 'textbox3')" maxlength="2" /><br><br>
          Enter a Number : <input type="text" name="textbox3" id="textbox3"  onkeyup="movetoNext(this, 'textbox4')" maxlength="2" /><br><br>
          Enter a Number : <input type="text" name="textbox4" id="textbox4"  onkeyup="movetoNext(this, 'textbox5')" maxlength="2" /><br><br>
          Enter a Number : <input type="text" name="textbox5" id="textbox5"  onkeyup="movetoNext(this, 'textbox6')" maxlength="2"/><br><br>

         <input type="text" name="textbox6" id="textbox6"/>
         <button onclick="myFunction()" value="answer">search</button>
         <script>
function movetoNext(current, nextFieldID) {
if (current.value.length >= current.maxLength) {
    document.getElementById(nextFieldID).focus();
}
         </script>
      </body>
    </html>
    
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:-2)

尝试下面的html

&#13;
&#13;
<!DOCTYPE html>
<html>
<body>

<form name="myform" >
  First number:<br>
  <input type="text" name="1" value="211">
  <br>
  Last number:<br>
  <input type="text" name="2" value="1223">
  <br><br>
  <input type="submit" value="Search" onclick="search()">
</form> 

<script>
 function search(val){
       var x = document.getElementById("myform").elements.length;
       console.log(x);
      var val = ['112','1213','1234','121','142']
      // we need check the form value exist in array or not 
  }
<script>

</body>
</html>
&#13;
&#13;
&#13;