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>

posted @ 2017-07-24 16:55  梁大爷  阅读(307)  评论(0编辑  收藏  举报