js判断复选框是否选中及选中个数的实现代码
作者:jingxian 时间:2024-04-22 22:17:03
用js判断复选框是否选中及选中个数,以前经常有朋友提到复选框的选中问题,这段代码可以帮你解决这个问题,而且它还可以判断你选择了多少个复选框,多选则弹出提示
<HTML>
<head>
<title>判断复选框是否选中及选中个数</title>
<SCRIPT LANGUAGE="JavaScript">
function countChoices(obj) {
max = 2;
box1 = obj.form.box1.checked;
box2 = obj.form.box2.checked;
box3 = obj.form.box3.checked;
count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0);
if (count > max) {
alert("对不起,你只能选择" + max + "个!");
obj.checked = false;
}
}
//-->
</script>
<body>
<form name="form">
你喜欢的语言是(最多两个): <p>
<input type=checkbox name=box1 onClick="countChoices(this)">ASP.NET<p>
<input type=checkbox name=box2 onClick="countChoices(this)">JAVA<p>
<input type=checkbox name=box3 onClick="countChoices(this)">C#<p>
</form>
</body>
</html>
标签:js,复选框
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
pandas按条件筛选数据的实现
2021-10-04 03:07:54
![](https://img.aspxhome.com/file/2023/4/105564_0s.png)
ASP实现GB2312字符与区位码的相互转换
2009-12-28 10:27:00
windows10下python3.5 pip3安装图文教程
2023-02-25 02:06:44
![](https://img.aspxhome.com/file/2023/0/120610_0s.png)
Python制作动态字符图的实例
2023-11-02 07:17:18
![](https://img.aspxhome.com/file/2023/7/131687_0s.png)
Python小白垃圾回收机制入门
2022-05-20 04:38:42
Go singleflight使用以及原理
2024-04-27 15:31:09
![](https://img.aspxhome.com/file/2023/2/134202_0s.png)
转换字符串单词的第一个字母为大写
2007-10-18 10:50:00
网页设计标准尺寸
2008-06-15 15:21:00
Python MySQL数据库基本操作及项目示例详解
2024-01-13 06:15:27
Python整型运算之布尔型、标准整型、长整型操作示例
2021-01-28 06:39:15
![](https://img.aspxhome.com/file/2023/6/97736_0s.jpg)
Mysql事物锁等待超时Lock wait timeout exceeded;的解决
2024-01-22 03:51:08
SQL 实现某时间段的统计业务
2024-01-24 11:41:03
![](https://img.aspxhome.com/file/2023/9/102049_0s.png)
Tensorflow的可视化工具Tensorboard的初步使用详解
2021-06-12 18:32:06
![](https://img.aspxhome.com/file/2023/5/79595_0s.jpg)
Python实现购物评论文本情感分析操作【基于中文文本挖掘库snownlp】
2022-10-18 11:45:34
![](https://img.aspxhome.com/file/2023/9/72249_0s.png)
如何用Matplotlib 画三维图的示例代码
2023-03-02 15:16:08
![](https://img.aspxhome.com/file/2023/2/118542_0s.png)
Python使用Pickle模块进行数据保存和读取的讲解
2021-08-23 19:37:55
细数nn.BCELoss与nn.CrossEntropyLoss的区别
2021-04-16 16:29:28
![](https://img.aspxhome.com/file/2023/2/72802_0s.jpg)
SpringBoot集成JPA持久层框架,简化数据库操作
2024-01-16 11:42:38
MySQL8下忘记密码后重置密码的办法(MySQL老方法不灵了)
2024-01-17 11:38:49
![](https://img.aspxhome.com/file/2023/1/102371_0s.jpg)
用js封装的时间设置器
2013-08-04 23:28:46