如何在Jquery中获取选中的复选框列表值
在这篇文章中,我们将看到如何从jquery中的复选框列表中获取选中的复选框值,这里我们将使用checkbox jquery获取多个选中的复选框值。例如,如果您在表行中有多个复选框,我们将在jquery中的数组或字符串中获取选中的复选框值。
在这个例子中,我添加了一些jquery代码、html checkbox和bootstrape cdn以及jquery链接。
<html>
<head>
<title>使用jquery从复选框列表中获取选定的复选框值-itdot.cn</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<div class="container" style="border:1px solid gray; margin-top: 20px;">
<h3 class="text-center">使用jquery从复选框列表中获取选定的复选框值-itdot.cn</h3>
<div style="margin-left: 210px;">
<input type="checkbox" id="id1" value="PHP"/> <label>PHP</label> <br>
<input type="checkbox" id="id2" value="jQuery"/> <label>jQuery</label> <br>
<input type="checkbox" id="id3" value="CSS"/> <label>CSS</label> <br>
<input type="checkbox" id="id4" value="Bootstrap"/> <label>Bootstrap</label> <br>
<input type="checkbox" id="id5" value="Laravel"/> <label>Laravel</label> <br><br>
<input type="button" id="btn" value="Submit" class="btn btn-primary" style="margin-bottom: 20px;" />
</div>
</div>
</body>
<script type="text/javascript">
$(function () {
$("#btn").click(function () {
var selected = new Array();
$("input[type=checkbox]:checked").each(function () {
selected.push(this.value);
});
if (selected.length > 0) {
alert("Selected items: " + selected.join(","));
}
});
});
</script>
</html>

- 上一篇:什么是CSS?
- 下一篇:你应该避免的5个常见的HTML错误
相关问题
- 2021-09-29 你应该避免的5个常见的HTML错误
- 2021-09-26 什么是CSS?
- 2021-09-16 浏览器如何显示表格数据默认样式
- 2021-09-15 list-style-image属性的作用是什么?
- 2021-09-07 Div+CSS页面布局有什么优势?
您的见解
已有 0 条答案
- 热门排行
- 最新答案
-
-
如何避免重复提交表单页
binary options system strategy page 回答 2022-04-01 03:42:00
-
如何确定PHP是否适合我的网站或WordPress?
แอพเปลี่ยนรูปเป็นภาพวาด 回答 2022-03-27 18:27:12
-
自动缓存对动态页面的影响
50 deposit binary options 回答 2022-03-24 05:31:20
-
如何避免重复提交表单页
free binary options signals providers of goods 回答 2022-03-20 12:29:02
-
如何避免重复提交表单页
binary options strategy 5 minutes 15 min no loss acord 回答 2022-03-20 09:44:29
-