开发者

select and deselect all checkboxes

开发者 https://www.devze.com 2022-12-14 15:04 出处:网络
<script type=\"text/javascript\"> $(document).ready(function() { $(\"#paradigm_all\").click(function() {
<script type="text/javascript">
$(document).ready(function() {
    $("#paradigm_all").click(function() {
        var checked_status = this.checked;
        $("input[@name=paradigm]").each(function() {
            this.checked = checked_status;
        });
    });
});

</script>


<table class="data-table">
  开发者_运维技巧  <tr>
         <th>
            Redni br.
        </th>
        <th>
            Br. Indexa
        </th>
        <th>
            Prezime
        </th>
        <th>
            Ime
        </th>
        <th>
           <input id="paradigm_all" type="checkbox" />
        </th>  
    </tr>       
<% int rb = 1;%>
<% foreach (var item in Model)
   { %>       
    <tr>
    <td>
            <input readonly="readonly" class="input-box" id="rb" type="text" name="rb"  value="<%= Html.Encode(rb)%>" />
        </td>            
        <td>

            <input readonly="readonly" class="input-box" id="id_stud" type="text" name="id_stud"  value="<%= Html.Encode(item.id_stud)%>" />

        </td>
        <td>
            <%= Html.Encode(item.prezime)%>
        </td>
        <td>
             <%= Html.Encode(item.ime)%>
        </td>
         <td>
           <input  name="paradigm" type="checkbox" /> 
        </td>
    </tr>

<% rb = rb + 1;%>
<% } %>

</table>

Why this java script does not work? Pls help


   $("input[@name=paradigm]").attr('checked',checked_status);

The reason yours doesn't worked is because $('...').checked is a value return, not a reference. To change the checked attribute, you need to use the attr setter.


I think you can safely remove the each from this code

$(document).ready(function() {
   $("#paradigm_all").click(function() {
    $("input[name=paradigm]").attr({checked: $(this).is(':checked')});
  });


Add on the top of the table checkbox element

<table>
<tr>
 <th>
  <input type="checkbox" onclick="$('table:parent td input[type=checkbox]').attr('checked',$(this).attr('checked'));" />
 </th>

... etc.

<tbody>                 
 <tr>
  <td><input type="checkbox" id="id-1" name="id[]" value="1" /></td>                       
 </tr>
</tbody>
</table>

First checkbox check all checkboxes inside table.


Woah dude, you have some crazy things going on here, I suggest cleaning up the way it was pasted here, I think we could read it better then.

0

精彩评论

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

关注公众号