开发者

Checkboxes which are in first cell of every row , If check box is checked than show that row values?

I tried to do something..., Bellow code alerting only if all check boxes are checked. How to do this, please help me.

<script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
     $("#c1,#c2,#c3").click(function()
     {

        if($("#tbl").find('tr:first').find('input:checkbox').is(':checked')==true)
        {开发者_开发问答
             alert("checked");
          //get the column values of that row.
          //$("#result").html();
        }
     });
});
</script>
<!-- Table--- -->
<table border="1" id="tbl">
          <tr>
               <td><input type="checkbox" id="c1"></td>
               <td>value 01</td>
               <td>value 02</td>
               <td>value 03</td>
          </tr>
          <tr>
              <td><input type="checkbox" id="c2" ></td>
               <td>value 11</td>
               <td>value 12</td>
               <td>value 13</td>
          </tr>
          <tr>
               <td><input type="checkbox" id="c3"></td>
               <td>value 21</td>
               <td>value 22</td>
               <td>value 23</td>
          </tr>
</table>

<!-- show result -->
<div id="result"></div>


var $result = $('#result');
$('#tbl tr td :checkbox').change(function(){
    var $this = $(this),
        $tr = $this.closest('tr'),
        text = $tr.find('td:not(:first)').text();
    if($this.is(':checked')){
        $result.html($result.html()+text);
    } else{
        $result.html($result.html().replace(text, ''));
    }
});

Demo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜