checkbox

CSDNyongwei 2011-05-18 11:32:04
怎样JAVAscript 中判断一个复选框是否已经选定
function checkbox(){
var tr=document.getElementById("td");
.
.

if()
}


<table>

<tr id="td" >
<td><input type="ckeckbox"></td>
<tr>
<input type="button" onclick="checkbox();">
</table>


那一部分怎么写 能不能 不用 chcked="checked"
...全文
102 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
happy664618843 2011-05-24
  • 打赏
  • 举报
回复
jquery
if($(this).is(":checked"))
...
or if($(this).get(0).checked)

CSDNyongwei 2011-05-23
  • 打赏
  • 举报
回复
呵呵呵 谢谢大家 !!!
我明白了
lf_net 2011-05-19
  • 打赏
  • 举报
回复
上面都是正解
hch126163 2011-05-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 acesidonu 的回复:]

if (chk.checked) {alert('选中了');}
[/Quote]

++++

js checked 的值就是 true or false
IT流渊 2011-05-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 t5500 的回复:]
HTML code
<script>
function checkbox(){
var chk=document.getElementById("td").getElementsByTagName('input')[0];
if (chk.checked == true) alert('YES');
else alert('NO');
}
</script>
……
[/Quote]

推荐
Acesidonu 2011-05-19
  • 打赏
  • 举报
回复
if (chk.checked) {alert('选中了');}
hj_545 2011-05-19
  • 打赏
  • 举报
回复
chk.checked 返回的是一个boolean值
而不是checked的值,选中是checked没选中是""

乌镇程序员 2011-05-18
  • 打赏
  • 举报
回复
<script>
function checkbox(){
var chk=document.getElementById("td").getElementsByTagName('input')[0];
if (chk.checked == true) alert('YES');
else alert('NO');
}
</script>
<table>
<tr id="td">
<td><input type="checkbox" name="chk" /></td>
<tr>
</table>
<input type="button" onclick="checkbox();" value="点我" />

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧