作者TonyQ (沉默是金)
看板Ajax
标题Re: [问题] jquery 抓取值 的问题
时间Mon Dec 22 22:34:05 2008
※ 引述《drinks (爪哇工程师)》之铭言:
: <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;
: })
↑这个filter没有任何意义吧?
.each( function(){
: alert($(this).children(".chk").checked );
^^^^^^^这个This是 tr ,
tr 的children 是指他底下的那一层 td ,
所以你捞不到 checkbox.
你应该用find会比较理想,find会深入查找.
$(this).find(".chk");
: //这边 如果可以抓到.checked ,那就可以用if else把数字累加
: //可是 alert的值 都是undefinded
: alert($(this).children(".add").text() );
: //这边可以抓到正确的值
: });
: });
: });
: </script>
: 不好意思 写的有点乱,
: 请问有人知道我错在哪里吗?
: 感谢回答!
--
What do you want to have ? / What do you have?
从书本中,你可以发现我的各种兴趣。
从CD中,你可以了解我所喜欢的偶像明星。
或许从文字你很难以了解一个人,但从物品可以。
My PPolis , My past. http://ppolis.tw/user/Tony
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 221.169.78.140
1F:推 drinks:感谢回答! 12/23 12:55