js同时获取多个同name的input框的值
demo代码
1 <!doctype html> 2 <html ng-app="a3_4"> 3 <head> 4 <title>表头排序</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6 <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> 7 <!--<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">--> 8 <script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script> 9 10 </head> 11 <body> 12 <div ng-controller="c3_4"> 13 <input type="text" name="abcd" value=""/> 14 <input type="text" name="abcd" value=""/> 15 <input type="text" name="abcd" value=""/> 16 <input type="text" name="abcd" value=""/> 17 18 <button ng-click="getValues()">点击获取input值</button> 19 20 </div> 21 <script type="text/javascript"> 22 var a3_4 = angular.module('a3_4', []); 23 a3_4.controller('c3_4', ['$scope', function ($scope) { 24 $scope.getValues = function(){ 25 var els =document.getElementsByName("abcd"); 26 for (var i = 0, j = els.length; i < j; i++){ 27 console.log(els[i].value); //获得值<br>alert(els[i].id); //获得ID 28 } 29 } 30 }]) 31 </script> 32 </body> 33 </html>
运行演示