DOM操作表單
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function getFormInformation(){
var myform = document.forms[0];
alert(myform.id+myform.method+myform.target);
myform.submit(); //提交表單
}
</script>
</head>
<body>
<form id="testform" action="http://www.baidu.com" method="get" target="_blank">
<input name="username" type="text" value="請輸入密碼" /><br />
<input name="pwd" type="password" value="123" /><br />
<select name="city">
<option value="CD">成都</option>
<option value="SH" selected="selected">上海</option>
</select><br />
<input type="button" value="Get number one" onclick="var n = document.getElementById(‘testform‘).elements[0].value;alert(n);"/><br />
<input type="button" value="Get number two" onclick="alert(document.getElementById(‘testform‘).elements[‘pwd‘].value);"/><br />
<input type="button" value="Get number three" onclick="alert(document.getElementById(‘testform‘).city.value);"/><br />
<input type="button" value="Get more information" onclick="getFormInformation()"/>
</form>
</body>
</html>
DOM操作表單