JQuery復(fù)選框全選效果如何實(shí)現(xiàn)
Js相關(guān)技術(shù)
checked屬性
如何獲取所有復(fù)選框:document.getElementsByName、
需求分析
在我們對(duì)表格處理的時(shí),有些情況下,我們需要對(duì)表格進(jìn)行批量處理
技術(shù)分析
第一種方法:選擇器[屬性名稱='屬性值']
$("input[type='checkbox']:gt(0)").prop("checked",this.checked);
第二種方法:使用層級(jí)選擇器來(lái)實(shí)現(xiàn) tbody > tr > td > input
$("tbody > tr > td > input").prop("checked",this.checked);
第三種方法:
// #tab > tbody > tr:nth-child(4) > td:nth-child(1) > input[type="checkbox"]
代碼實(shí)現(xiàn)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="../js/jquery-1.11.0.js" ></script> <script> /* 表格全選和全不選 進(jìn)一步確定事件: 點(diǎn)擊事件 */ $(function(){ //綁定點(diǎn)擊事件 //this 代表的是當(dāng)前函數(shù)的所有者 $("#checkAll").click(function(){ //獲取當(dāng)前選中狀態(tài) // alert(this.checked); //獲取所有分類項(xiàng)的checkbox // 選擇器[屬性名稱='屬性值'] // $("input[type='checkbox']:gt(0)").prop("checked",this.checked); //使用層級(jí)選擇器來(lái)實(shí)現(xiàn) tbody > tr > td > input // $("tbody > tr > td > input").prop("checked",this.checked); //這個(gè)可行 // #tab > tbody > tr:nth-child(4) > td:nth-child(1) > input[type="checkbox"] $("input").prop("checked",this.checked); }); }); </script> </head> <body> <table border="1px" width="600px" id="tab"> <thead> <tr > <td> <input type="checkbox" id="checkAll" /> </td> <td>分類ID</td> <td>分類名稱</td> <td>分類商品</td> <td>分類描述</td> <td>操作</td> </tr> </thead> <tbody> <tr> <td> <input type="checkbox" /> </td> <td>1</td> <td>手機(jī)數(shù)碼</td> <td>華為,小米,尼康</td> <td>黑馬數(shù)碼產(chǎn)品質(zhì)量最好</td> <td> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>|<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a> </td> </tr> <tr> <td> <input type="checkbox" /> </td> <td>2</td> <td>成人用品</td> <td>充氣的</td> <td>這里面的充氣電動(dòng)硅膠的</td> <td><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>|<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a></td> </tr> <tr> <td> <input type="checkbox" /> </td> <td>3</td> <td>電腦辦公</td> <td>聯(lián)想,小米</td> <td>筆記本特賣</td> <td><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>|<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a></td> </tr> <tr> <td> <input type="checkbox" /> </td> <td>4</td> <td>饞嘴零食</td> <td>辣條,麻花,黃瓜</td> <td>年貨</td> <td><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>|<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a></td> </tr> <tr> <td> <input type="checkbox" /> </td> <td>5</td> <td>床上用品</td> <td>床單,被套,四件套</td> <td>都是套子</td> <td><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >修改</a>|<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >刪除</a></td> </tr> </tbody> </table> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- bootstrap+jQuery 實(shí)現(xiàn)下拉菜單中復(fù)選框全選和全不選效果
- JQuery實(shí)現(xiàn)列表中復(fù)選框全選反選功能封裝(推薦)
- jQuery對(duì)checkbox 復(fù)選框的全選全不選反選的操作
- js與jQuery實(shí)現(xiàn)checkbox復(fù)選框全選/全不選的方法
- jQuery實(shí)現(xiàn)復(fù)選框全選/取消全選/反選及獲得選擇的值
- jQuery判斷checkbox(復(fù)選框)是否被選中以及全選、反選實(shí)現(xiàn)代碼
- jquery復(fù)選框全選/取消示例
- JQUERY復(fù)選框CHECKBOX全選,取消全選
相關(guān)文章
jquery-1.2.6得到焦點(diǎn)與失去焦點(diǎn)的寫法
jquery-1.2.6得到焦點(diǎn)與失去焦點(diǎn)的實(shí)現(xiàn)方法。點(diǎn)擊“運(yùn)行”后,請(qǐng)刷新一次。2009-05-05jQuery UI Dialog控件中的表單無(wú)法正常提交的解決方法
研究了頁(yè)面源碼后發(fā)現(xiàn),jQuery UI Dialog控件初始化時(shí)動(dòng)態(tài)生成的HTML元素被添加到頁(yè)面的尾部、form元素的后面,而原始的Dialog模板部分(其內(nèi)包含表單元素)也被移到了 動(dòng)態(tài)生成的HTML元素內(nèi)。2010-12-12jquery 觸發(fā)a鏈接點(diǎn)擊事件解決方案
使用jquery為a連接綁定點(diǎn)擊事件,具體代碼如下,感興趣的朋友可以參考下,希望可以幫助到你2013-05-05jQuery 練習(xí)[一] 學(xué)習(xí)jquery的準(zhǔn)備工作
初次嘗試 jQuery, 近乎震撼! 簡(jiǎn)潔、高效、優(yōu)雅、平易, 太有思想了.2010-05-05jquery實(shí)現(xiàn)簡(jiǎn)單的彈窗效果
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)簡(jiǎn)單的彈窗效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10使用異步controller與jQuery實(shí)現(xiàn)卷簾式分頁(yè)
這篇文章主要介紹了使用異步controller與jQuery實(shí)現(xiàn)卷簾式分頁(yè),使用異步controller與jQuery按需加載內(nèi)容,當(dāng)用戶開始通過(guò)網(wǎng)站的內(nèi)容滾動(dòng)時(shí)進(jìn)一步加載內(nèi)容。,需要的朋友可以參考下2019-06-06