分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

JQuery获取input checkbox

发布时间:2023-09-06 01:24责任编辑:彭小芳关键词:checkbox
// 全选 ??????$(‘#allcheck‘).click(function(){ ???????$(‘input[name="check"]‘).prop(‘checked‘,‘true‘); ???}); ???//反选 ???$(‘#reversecheck‘).click(function(){ ???????$(‘input[name="check"]‘).each(function () { ???????????$(this).prop("checked", !$(this).prop("checked")); ???????}); ???});
被选中的值代码:<html> ???<head> ???????<meta charset="gbk"> ???????<!-- 引入JQuery --> ???????<script src="jquery-1.3.1.js" type="text/javascript"></script> ???</head> ???<body> ???????<input type="checkbox" value="橘子" name="check">橘子1</input> ???????<input type="checkbox" value="香蕉" name="check">香蕉1</input> ???????<input type="checkbox" value="西瓜" name="check">西瓜1</input> ???????<input type="checkbox" value="芒果" name="check">芒果1</input> ???????<input type="checkbox" value="葡萄" name="check">葡萄1</input> ???????????????<input type="button" value="方法1" id="b1"> ???????<input type="button" value="方法2" id="b2"> ???</body> ???????<script> ???????//方法1 ???????$("#b1").click(function(){ ???????????//$(‘input:checkbox:checked‘) 等同于 $(‘input[type=checkbox]:checked‘) ???????????//意思是选择被选中的checkbox ???????????$.each($(‘input:checkbox:checked‘),function(){ ???????????????window.alert("你选了:"+ ???????????????????$(‘input[type=checkbox]:checked‘).length+"个,其中有:"+$(this).val()); ???????????}); ???????}); ???????????????//方法2 ???????$("#b2").click(function(){ ???????????$.each($(‘input:checkbox‘),function(){ ???????????????if(this.checked){ ???????????????????window.alert("你选了:"+ ???????????????????????$(‘input[type=checkbox]:checked‘).length+"个,其中有:"+$(this).val()); ???????????????} ???????????}); ???????}); ???</script></html>

  

JQuery获取input checkbox

原文地址:http://www.cnblogs.com/liuzhiw/p/7823486.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved