本文主要介绍了jquery实现遍历复选框的方法,结合实例形式分析了jquery针对表单复选框元素的遍历与字符串操作相关技巧,需要的朋友可以参考下,希望能帮助到大家。
1、问题背景:
这里有10个复选框,根据选择的复选框获取其值,并将其值用“——”连接,插入到p中
2、实现代码:
html>
<meta>
<title>遍历复选框</title>
<script></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
var str = "";
$("input[name='ckb']").each(function(){
if($(this).is(":checked"))
{
str += "——" + $(this).val();
}
});
$("#txt").html(str);
});
});
</script>
<p>
<input>1
<input>2
<input>3
<input>4
<input>5
<input>6
<input>7
<input>8
<input>9
<input>10<br>
<input>
</p><p></p>
3、运行效果图:

jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
相关推荐:
JQuery查找子元素find()和遍历集合each的方法实例分享










