2011-06-03 107 views
0

我有這個表,從中我想選擇所有的td元素值,如果複選框是checked,然後把所有的元素在一些數組或字符串,這樣我可以轉移它到服務器端。選擇td元素複選框是

<table id="tableDg"> 
    <tbody> 
    <tr> 
    <td><input type="checkbox" class = "chkbCsm" ></input></td> 
     <td width="10%" align="center">&nbsp;&nbsp;<input type="hidden" id="nameText" readonly="true" value="{name}">{name}</input></td> 
     <td width="22%" align="center">&nbsp;&nbsp;<input type="hidden" id="nameText" readonly="true" value="{host}">{host}</input></td> 
    </tr> 
    </tbody> 
</table> 

下面是我在做什麼jQuery的一面,但不管做選擇的事情複選框的正對。請有人幫我解決一些問題。

$('#tableDg tbody tr').live('click', function (event) { 
    $(this).find('td').each(function(index, item) { 
     if ($(this).has(':hidden')) { 
      alert($(this).find(':hidden').val()); 
     } 
    }); 
}); 

新增一個的jsfiddle鏈接

看看here

回答

1
$('#tableDg tbody tr').live('click', function (event) { 
    if ($('input.chkbCsm', this).is(':checked')) 
    { 
     $('input:hidden', this).each(function() { 
      alert(this.value); 
     }); 
    } 
}); 
0

如果複選框,在您的代碼進行覈對或不你不檢查。

if($(".chkbCsm:checkbox").is(":checked") 
{ 
    $(this).find('td').each(function(index, item) { 
    if ($(this).has(':hidden')) { 
     alert($(this).find(':hidden').val()); 
    } 
    });  
}