html 获取控件值。

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
  <table id="projectTable">
    <tr>
        <td>CRP</td><td id="1" name="CRP"><input type="text" id="1" class="project"></td>
    </tr>
    <tr>
        <td>HCG</td><td id="2" name="HCG"><input type="text" id="32" class="project"></td>
    </tr>
    <tr>
        <td>HBP</td><td id="3" name="HBP"><select id="332" class="project"><option value="1" >A</option><option value="2">B</option></select></td>
    </tr>
    <tr>
        <td>AFP</td><td id="4" name="AFP"><select id="555" class="project"><option value="1">A</option><option value="2" >B</option></select></td>
    </tr>
  </table>

  <input type="button" onclick="save()">

  <script>
    function saveTo(){
        var tab = document.getElementById('projectTable'); //获取table对象
        var row = tab.rows; //获取table的行
        var cell = row[2].cells; //获取第二行的列
        alert(cell[1].name); //获取第三列的值
    }


    function save() {
        var arr = document.getElementsByClassName("project");
        for(var i=0; i<arr.length; i++) {
            var item = arr[i];
            var result = item.value;
            var id = item.id;
            alert(result + ":" + id);
        }
    }
  </script>
 </body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_38719039/article/details/82142243
今日推荐