JavaScript基础教程

文章39 |   阅读 11475 |   点赞0

来源:https://blog.csdn.net/u011541946/category_6887610.html

JavaScript学习笔记36-操作form

x33g5p2x  于2022-03-06 转载在 其他  
字(0.6k)|赞(0)|评价(0)|浏览(279)

本文介绍JavaScript操作HTML中的form元素,例如一个登陆框。

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html>  
<head>  
</head>  
<body>  
<form>
	Username: <input type="text" />
	Password: <input type="password" />
	<input type ="submit" value="提交" />

</form>
<script type="text/javascript">
	var x = document.forms[0].length;
	document.write(x);

</script>  

</body>  
</html>

上面的forms[0]代表上面的form,这里我们只有一个form,length表示控件的数量,当前有用户名输入框和密码输入框和提交按钮,三个控件。

相关文章