[問題] jquery 抓取值 的問題

看板Ajax作者 (爪哇工程師)時間16年前 (2008/12/22 21:46), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
小弟在寫 form 表單 用jquery 抓取值的時候 遇到一些問題 我的 .html 是這樣的 <form > <table id="table1"> <tr> <td><input type="checkbox" class="all"></td> <td>數字</td> </tr> <tr class="addtr"> <td><input type="checkbox" class="chk"></td> <td class="add">123</td> </tr> <tr class="addtr"> <td><input type="checkbox" class="chk"></td> <td class="add">456</td> </tr> </table> </form> 以下是 jquery 程式碼 <script type="text/javascript"> $(document).ready(function(){ $('#clickAll').click(function(){//全選 if (this.checked){ $("#table1 input:checkbox.chk").attr('checked','checked'); }else{ $("#table1 input:checkbox.chk").attr('checked',''); } }); //第二個 我是想要在 checkbox有點選的時候 將td的數字相加 //我寫的方法 抓不到check box .checked $("#table1 input:checkbox.chk").click(function () { var total = 0; $('#table1 tr.addtr').filter(function(){ return this; }).each( function(){ alert($(this).children(".chk").checked ); //這邊 如果可以抓到.checked ,那就可以用if else把數字累加 //可是 alert的值 都是undefinded alert($(this).children(".add").text() ); //這邊可以抓到正確的值 }); }); }); </script> 不好意思 寫的有點亂, 請問有人知道我錯在哪裡嗎? 感謝回答! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.139.12
文章代碼(AID): #19Jvf0nD (Ajax)
文章代碼(AID): #19Jvf0nD (Ajax)