怎样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"

解决方案 »

  1.   

    <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="点我" />
      

  2.   

    if (chk.checked) {alert('选中了');}
      

  3.   


    ++++js  checked 的值就是 true or  false
      

  4.   

    chk.checked 返回的是一个boolean值
    而不是checked的值,选中是checked没选中是""
      

  5.   

    jquery
    if($(this).is(":checked"))
    ...
    or if($(this).get(0).checked)