jquery實現(xiàn)全選和取消全選 利用jQuery實現(xiàn)CheckBox全選/全不選/反選的簡單代碼?
利用jQuery實現(xiàn)CheckBox全選/全不選/反選的簡單代碼?jquery怎么實現(xiàn)全選復(fù)選框?1。為所有框定義一個ID,例如:<input type=“checkbox”ID=“cball”V
利用jQuery實現(xiàn)CheckBox全選/全不選/反選的簡單代碼?
jquery怎么實現(xiàn)全選復(fù)選框?
1。為所有框定義一個ID,例如:
<input type=“checkbox”ID=“cball”Value=“all”>全選
2。為其他復(fù)選框定義相同的名稱,例如:
嗜好:<input type=“checkbox”name=“cbhobby”value=“song”>唱歌<input type=“checkbox”name=“cbhobby”value=“dance”<input type=“checkbox”name=“cbhobby”value=“play”>玩游戲<input type=”checkbox“Name=”cbhobby“value=”eat“>吃美味的食物<input type=”checkbox“Name=”cbhobby“value=”sleep“>
3。編寫jQuery代碼,使復(fù)選框的選定屬性與單擊“全部”復(fù)選框時“全部”復(fù)選框的選定屬性一致
<script type=“text/JavaScript”SRC=“JS/jQuery。1.8.3 最小js“></script><script type=”text/javascript“>$(function(){$(”cbAll“)。單擊(function(){$(”input[name=”cbHobby“]”).prop(”checked“,$(this).prop(”checked“)})</script>
代碼示例:
JS reverse selection/select all
JS is writed by”在標(biāo)題行中添加“全選”復(fù)選框和“反向選擇”按鈕,并在數(shù)據(jù)行中添加帶有“名稱”屬性的復(fù)選框。
&Lttable border=“1”align=“center”width=“80%”>
<tr>
<TH><input
type=“checkbox”id=“checkall”onclick=“checkall()”/><input
type=“button”value=“invert selection”onclick=“invertchk()”/></th>
<TH>主鍵序號</th>
</TR>
<tbody>
<c:forEach項="${ 頁面列表}“
var=”recruit“>
<tr align=”center“>
<td><input type=”checkbox“
name=”checkid“value=”${招聘.nid}“/></td>
<td>${招聘.nid}</td>
<td>${招聘.cjob}</td>
</tr>
</c:forEach>
</tbody>
</table>