31前端基础 -JQuery之 表单选择器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_20042935/article/details/88616275

JQuery之 表单选择器

关键字:

  • :input 只要是form的子标签 就会被选中
  • input 直选中标签为input的元素

效果图:

在这里插入图片描述

代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>09-表单选择器.html</title>
		<!--   引入jQuery -->
		<script src="../js/jquery-1.11.0.min.js"></script>
		<script src="../js/assist.js"></script>
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<script type="text/javascript">
			$(function() {
				$("#btn1").click(function() {
					alert($(":input").length);
				})
			});
		</script>
	</head>

	<body>
		<input type="button" value="选取所有的表单子元素" id="btn1" /><br />

		<form id="form1" action="#">
			<input type="button" value="Button" /><br/>
			<input type="checkbox" name="c" />1<input type="checkbox" name="c" />2<input type="checkbox" name="c" />3<br/>
			<input type="file" /><br/>
			<input type="hidden" /><br/>
			<input type="image" src="1.jpg" /><br/>
			<input type="password" /><br/>
			<input type="radio" name="a" />1<input type="radio" name="a" />2<br/>
			<input type="reset" /><br/>
			<input type="submit" value="提交" /><br/>
			<input type="text" /><br/>
			<select>
				<option>Option</option>
			</select><br/>
			<textarea rows="5" cols="20"></textarea><br/>
			<button>Button</button><br/>
		</form>

		<div></div>
	</body>

</html>

猜你喜欢

转载自blog.csdn.net/qq_20042935/article/details/88616275
今日推荐