<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题页</title>
<script src="jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">
//each
$(function(){
$('input[name=names]').click(function(){
var arr = new Array();
$('input[name=names]:checked').each(function(key,value){
arr[key]= $(value).val();
});
$('#msg').text(arr.length + arr.join(","));
});
});
</script>
</head>
<body>
<input type="checkbox" name="names" value="北京"/>背景 <br/>
<input type="checkbox" name="names" value="合肥"/>合肥 <br/>
<input type="checkbox" name="names" value="苏州"/>苏州 <br/>
<input type="checkbox" name="names" value="南京"/>南京 <br/>
<div id="msg"></div>
<input type="button" value="显示选中项"/> <br/>
</body>
</html>
Jquery系列-Jquery each的使用
最新推荐文章于 2024-03-13 07:00:00 发布