1. 程式人生 > >form表單用js獲取值

form表單用js獲取值

<script>
 function checkForm()
 {
  var inputList = document.getElementsByTagName("input");
  console.log(inputList.length); //獲取input的個數
//獲取單個的name的屬性和 input文字框的值
console.log(inputList[0].name+"<>"+inputList['0'].value); return false; }</script>
<form action="#" onsubmit="return checkForm()
"> 姓:<input type="text" name="name1"> 名:<input type="text" name="name2"> <input type="submit" value="提交">