<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>
<style type="text/css">
.waiting{color:gray};
</style>
<!--Radio Button-->
<script type="text/javascript">
$(function(){
$('#getValue').click(function(){
//获取选中
alert($(':radio[name=gender]:checked').val());
});
$('#setValue').click(function(){
//设置值
$(':radio[name=gender]').val(['女']);
$(':checkbox').val(['篮球','足球']);
//单独设置 修改checked属性即可
});
});
$(function(){
$('#setAll').click(function(){
$('#playlist :checkbox').attr('checked',true);
});
$('#setNull').click(function(){
$('#playlist :checkbox').attr('checked',false);
});
$('#setResever').click(function(){
$("#playlist :checkbox").each(function () {
$(this).attr("checked", !$(this).attr("checked"));
});
});
});
</script>
</head>
<body>
<input type="radio" value='男' name="gender"/>男<br>
<input type="radio" value='女' name="gender"/>女<br>
<input type="radio" value='保密' name="gender"/>保密<br>
<input type="checkbox" value='篮球' />篮球
<input type="checkbox" value='足球' />足球
<input type="checkbox" value='羽毛球' />羽毛球
<input type="checkbox" value='乒乓球' />乒乓球
<input type="button" value=取值 id="getValue">
<input type="button" value=设置 id="setValue">
<div id="playlist">
<input type="checkbox" value='歌曲1' />歌曲1<br>
<input type="checkbox" value='歌曲2' />歌曲2<br>
<input type="checkbox" value='歌曲3' />歌曲3<br>
<input type="checkbox" value='歌曲4' />歌曲4<br>
<input type="checkbox" value='歌曲5' />歌曲5<br>
</div>
<input type="button" value=全选 id="setAll">
<input type="button" value=全不选 id="setNull">
<input type="button" value=反选 id="setResever">
</body>
</html>
Jquery系列-Jquery操作radio和checkbox
最新推荐文章于 2019-03-19 22:19:32 发布