您好,登錄后才能下訂單哦!
這篇“thinkphp如何實(shí)現(xiàn)全選功能”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來(lái)看看這篇“thinkphp如何實(shí)現(xiàn)全選功能”文章吧。
thinkphp實(shí)現(xiàn)全選的方法:1、創(chuàng)建一個(gè)前端示例文件,并設(shè)置html按鈕;2、通過(guò)js代碼“l(fā)ayui.use('form', function () {...}”實(shí)現(xiàn)數(shù)據(jù)全部勾選;3、打開(kāi)thinkphp文件,通過(guò)“public function deleteAll(){...}”方法實(shí)現(xiàn)全選刪除操作即可。
thinphp5+html全選和反選和多選后刪除
最近研究了下按鈕的多選,大家可以看看,話(huà)不多說(shuō)上代碼
html按鈕
<input style="float: right;margin-left: 10px" type="checkbox" lay-skin="primary" id="c_all" lay-filter="c_all" title="全部">
<input style="float: right;margin-left: 10px" type="checkbox" lay-skin="primary" id="f_all" lay-filter="f_all" title="反選">
<input style="float:right;margin-top: 3.5px;margin-left:10px" type="button" id="btndelete" class="layui-btn layui-btn-sm" value="刪除">
js
<!-- 多選刪除 -->
<script type="text/javascript">
$('#btndelete').click(function(){
var a = document.getElementsByName("cityId");
var b=[];
for(i in a){
if(a[i].checked)
b.push(a[i].value);
}
if(b==""){alert('請(qǐng)選擇數(shù)據(jù)刪除')}else{
layer.confirm('確定要?jiǎng)h除?', function(index) {
window.location.href='/admin/commodity/deleteAll?b='+b;
})}
})
</script>
<!-- 全選框 -->
<script type="text/javascript">
layui.use('form', function () {
var form = layui.form;
//全選
form.on('checkbox(c_all)', function (data) {
var a = data.elem.checked;
if (a == true) {
$(".cityId").prop("checked", true);
form.render('checkbox');
} else {
$(".cityId").prop("checked", false);
form.render('checkbox');
}
});
//反選
form.on('checkbox(f_all)', function (data) {
var item = $(".cityId");
item.each(function () {
if ($(this).prop("checked")) {
$(this).prop("checked", false);
} else {
$(this).prop("checked", true);
}
})
form.render('checkbox');
});
//有一個(gè)未選中全選取消選中
form.on('checkbox(c_one)', function (data) {
var item = $(".cityId");
for (var i = 0; i < item.length; i++) {
if (item[i].checked == false) {
$("#c_all").prop("checked", false);
form.render('checkbox');
break;
}
}
//如果都勾選了 勾上全選
var all=item.length;
for (var i = 0; i < item.length; i++) {
if (item[i].checked == true) {
all--;
}
}
if(all==0){
$("#c_all").prop("checked", true);
form.render('checkbox');}
});
});
</script>
這個(gè)是跳到方法里進(jìn)行刪除
// 刪除全部
public function deleteAll(){
$b=input('b');
// Db::name('excel')->where('id','in',$b)->delete();
if(false == Db::name('commodity')->where('id','in',$b)->delete()) {
return $this->error('刪除失敗,請(qǐng)選擇要?jiǎng)h除的數(shù)據(jù)');
} else {
return $this->success('刪除成功','admin/commodity/index');
}
}
以上就是關(guān)于“thinkphp如何實(shí)現(xiàn)全選功能”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。