- ·上一篇文章:jquery动态按需加载返回顶部,结合简单jQuery动画
- ·下一篇文章:KindEditor得不到textarea值的解决方法
当前位置:K88软件开发 → 文章中心 → 编程语言 → JavaScript → JS01 → 文章内容
jquery获取checkbox表单值的最简单的方法
<
script src="
http://www.K88.NET/js/jquery.js"
>
<
/script>
<
script>
$(function()
{
$("
#b1"
).click(function()
{
result = new Array()
$("
[name=a1]:checked"
).each(function()
{
result.push($(this).val())
})
str = result.join("
,"
)
alert(str)
})
})
<
/script>
<
input type="
checkbox"
name="
a1"
id="
a1"
value="
1"
>
1<
input type="
checkbox"
name="
a1"
id="
a2"
value="
2"
>
2<
input type="
checkbox"
name="
a1"
id="
a3"
value="
3"
>
3<
input type="
checkbox"
name="
a4"
id="
a4"
value="
4"
>
4<
br />
<
input type="
button"
value="
点击"
id="
b1"
>
script src="
http://www.K88.NET/js/jquery.js"
>
<
/script>
<
script>
$(function()
{
$("
#b1"
).click(function()
{
result = new Array()
$("
[name=a1]:checked"
).each(function()
{
result.push($(this).val())
})
str = result.join("
,"
)
alert(str)
})
})
<
/script>
<
input type="
checkbox"
name="
a1"
id="
a1"
value="
1"
>
1<
input type="
checkbox"
name="
a1"
id="
a2"
value="
2"
>
2<
input type="
checkbox"
name="
a1"
id="
a3"
value="
3"
>
3<
input type="
checkbox"
name="
a4"
id="
a4"
value="
4"
>
4<
br />
<
input type="
button"
value="
点击"
id="
b1"
>
jquery获取checkbox表单值的最简单的方法