js - random basis for setting options drop-down box, get the value of a text box

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <select id="sel">
        < Option value = "Choose a randomized" > Choose a randomized </ Option > 
        < Option value = "cooked pork with rice" > cooked pork Bowl </ Option > 
        < Option value = "Gongbaojiding" > Gongbaojiding < / Option > 
        < Option ID = "OP" > dumplings </ Option > 
        < Option value = "fried cake" > fried bread </ Option > 
        <the Option value = "Sam Sun Bowl" > Sam Sun Bowl</option>
    </select>
    <input type="button"  value="随机" id="btn"/>
    <script src="common.js"></script>
  <script>
    var btn = document.getElementById('btn');
    btn.onclick =  function () {
       // make a selected option 
        //    var OP = document.getElementById ( 'OP'); 
        //    op.selected = to true; 
    // set randomly selected an option 
    var SEL = Document .getElementById ( ' SEL ' )
        var Options = sel.getElementsByTagName ( ' Option ' );
        // . 1 - options.length -. 1 
       // generates a random index 
       var index = getRandom ( . 1 , options.length -  . 1);
        // Get the index option 
       Options [index] .selected =  to true ;
    }
  </script>
  
</body>
</html>

And that we have to randomly display the drop-down box value using the button. Results are as follows

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="text"><br>
  <input type="radio"><br>
  <input type="button" value="按钮" id="btn"> 

  < Script > 
      // set in the text box 
      var Inputs = document.getElementsByTagName ( ' INPUT ' );
       var I =  0 , len = inputs.length;
       for (; I < len; I ++ )
      {
        // Get the collection element 
        var input = Inputs [I];
         // determines whether the current input is a text box 
        //    IF (input.type === 'text') { 
        //        input.value. 1 = I + 
        / /    } 
        IF (input.type ! ==  ' text ' ) {
             // not a text box 
            Continue ;
        }
        input.value = i + 1;
      }
      // 2 Click acquires the content of the text box, and with | separated 
       var BTN = document.getElementById ( ' BTN ' );
       btn.onclick =  function () {
            // find all the text box, the text box to obtain the value of 
           var ARR = [];
            for (I =  0 ; I < len; I ++ ) {
                var INPUT = Inputs [I];
                / / is determined whether the text box 
               iF (input.type ==!  ' text ' {)
                    Continue ;
               }
               arr.push(input.value);
               //arr[arr.length] = input.vale;

           }
           var str = arr.join('|');
           console.log(str);
       }
  </script>
</body>
</html>

The above is to obtain the value of the content box and down to | spaced effect is as follows

 

 By setting the text box

Guess you like

Origin www.cnblogs.com/awjbky/p/12162570.html