会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
liydotnet
博客园
首页
新随笔
联系
订阅
管理
JQuery:单选框,复选框取值
JQuery:单选框,复选框取值
<
div style
=
"
width:100%; border:solid 1px #0000ff; line-height:25px
"
>
<
input type
=
"
radio
"
name
=
"
items
"
id
=
"
item1
"
value
=
"
1
"
checked
=
"
checked
"
/
>1
<
input type
=
"
radio
"
name
=
"
items
"
id
=
"
item2
"
value
=
"
2
"/
>2
<
input type
=
"
radio
"
name
=
"
items
"
id
=
"
item3
"
value
=
"
3
"/
>3
<
input type
=
"
radio
"
name
=
"
items
"
id
=
"
item4
"
value
=
"
4
"/
>4
<
input type
=
"
radio
"
name
=
"
items
"
id
=
"
item5
"
value
=
"
5
"/
>5
<
br
/
>
<
input id
=
"
bt_radio
"
type
=
"
button
"
value
=
"
单选框测试
"
>
<
script type
=
"
text/javascript
"
>
$(document).ready(
function
()
{
$(
"
#bt_radio
"
).click(
function
()
{
alert($(
"
input[@name=items][@checked]
"
).val());
}
)
}
)
<
/
script>
<
/
div>
<
br
/
>
<
div style
=
"
width:100%; border:solid 1px #0000ff; line-height:25px
"
>
<
input type
=
"
checkbox
"
name
=
"
cbType1
"
id
=
"
cbType1
"
value
=
"
1
"
checked
/
>1
<
input type
=
"
checkbox
"
name
=
"
cbType1
"
id
=
"
cbType2
"
value
=
"
2
"
/
>2
<
input type
=
"
checkbox
"
name
=
"
cbType1
"
id
=
"
cbType3
"
value
=
"
3
"
checked
/
>3
<
input type
=
"
checkbox
"
name
=
"
cbType1
"
id
=
"
cbType4
"
value
=
"
4
"
checked
/
>4
<
br
/
>
<
input id
=
"
bt_checkbox
"
type
=
"
button
"
value
=
"
多选框测试
"
>
<
script type
=
"
text/javascript
"
>
$(document).ready(
function
()
{
$(
"
#bt_checkbox
"
).click(
function
()
{
var
aa
=
""
;
$(
"
input[@name=cbType1][@checked]
"
).each(
function
()
{
aa
+=
$(
this
).val()
+
"
,
"
;
}
)
alert(aa);
}
)
}
)
<
/
script>
<
/
div>
<
br
/
>
<
div style
=
"
width:100%; border:solid 1px #0000ff; line-height:25px
"
>
<
input type
=
"
checkbox
"
name
=
"
cbType2
"
id
=
"
cbType21
"
value
=
"
1
"
checked
/
>1
<
input type
=
"
checkbox
"
name
=
"
cbType2
"
id
=
"
cbType22
"
value
=
"
2
"
/
>2
<
input type
=
"
checkbox
"
name
=
"
cbType2
"
id
=
"
cbType23
"
value
=
"
3
"
checked
/
>3
<
input type
=
"
checkbox
"
name
=
"
cbType2
"
id
=
"
cbType24
"
value
=
"
4
"
checked
/
>4
<
br
/
>
<
input id
=
"
bt_checkbox2
"
type
=
"
button
"
value
=
"
多选框测试2
"
>
<
script type
=
"
text/javascript
"
>
$(document).ready(
function
()
{
$(
"
#bt_checkbox2
"
).click(
function
()
{
var
aa
=
""
;
$(
"
input[@name=cbType2]
"
).each(
function
()
{
if
(
this
.checked)
{
aa
+=
this
.value
+
"
,
"
;
}
}
)
alert(aa);
}
)
}
)
<
/
script>
<
/
div>
posted @
2008-04-02 11:33
liy
阅读(
6074
) 评论(
1
)
收藏
举报
刷新页面
返回顶部
公告