jquery中的全选、反选、全不选和单删、批删
HTML页面
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<center>
<table>
<tr>
<th><input type="checkbox" class="che"></th>
<th>ID</th>
<th>用户名</th>
<th>分类</th>
<th>编辑</th>
</tr>
{volist name="data" id="v"}
<tr id="{$v.id}">
<td><input type="checkbox" class="check" value="{$v.id}" name=bb></td>
<td>{$v.id}</td>
<td>{$v.biao}</td>
<td>{$v.fen}</td>
<td><a href="javascript:void (0);" class="shan">删除</a></td>
</tr>
{/volist}
</table>
<button class="pi_shan">批量删除</button>
<button class="quan">全选</button>
<button class="quanbu">全不选</button>
</center>
<script src="__STATIC__/js/jquery.min.js"></script>
<script>
//批删
$(document).on("click",".pi_shan",function () {
bb=document.getElementsByName("bb");
str="";
for (var i=0;i<bb.length;i++)
{
if(bb[i].checked==true)
{
str+=","+bb[i].value
}
}
str=str.substr(1);
//请求
$.post(
"{:url('index/pi_del')}",
{
id:str
},
function (data) {
if(data==1)
{
alert("批删成功");
location.href="{:url('index/show')}"
}else if(data==2)
{
alert("批删失败");
}
}
)
})
//全选
$(document).on("click",".quan",function () {
$(".check").prop("checked",true);
})
//反选
$(document).on("click",".quanbu",function () {
$(".check").prop("checked",false);
})
//反选
$(document).on("click",".che",function () {
$(".check").each(function () {
this.checked=!this.checked;
})
})
//单删
$(document).on("click",".shan",function () {
var id=$(this).parents("tr").attr("id");
//请求
$.post(
"{:url('index/dan_shan')}",
{
id:id
},function (data) {
if(data==1)
{
document.getElementById(id).remove()
}
}
)
})
</script>
</body>
</html> PHP页面
<?php
namespace app\index\controller; use think\Controller;
use think\Db;
use think\Request; class Index extends Controller
{
public function index()
{
return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ad_bd568ce7058a1091"></think>';
}
//展示页面
public function show()
{
$data=Db::table("title")->select();
return view("show",['data'=>$data]);
}
//单删
public function dan_shan()
{
$id=Request::instance()->param("id");
$a=Db::table("title")->where("id=$id")->delete();
if($a)
{
return 1;
}else{
return 2;
}
}
//批删
public function pi_del()
{
$id=Request::instance()->param("id");
$aa=explode(",",$id);
$a=Db::table("title")->delete($aa);
if($a)
{
return 1;
}else{
return 2;
}
}
}
jquery中的全选、反选、全不选和单删、批删的更多相关文章
- 表单javascript checkbox全选 反选 全不选
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- ajax全选、全不选、反选、单删/批删
<meta charset="utf-8"> <?php //链接数据库 $link = mysqli_connect('127.0.0.1','root','r ...
- 【HTML5】页面点击按钮添加一行 删除一行 全选 反选 全不选
页面点击按钮添加一行 删除一行 全选 反选 全不选 页面效果图如下 html页面代码 <!DOCTYPE html> <html> <head> & ...
- 表单Checkbox全选反选全不选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue实现单选多选反选全选全不选
单选 当我们用v-for渲染一组数据的时候,我们可以带上index以便区分他们我们这里利用这个index来简单地实现单选 <li v-for="(item,index) in radi ...
- checkbook全选/反选/全不选
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
- Jquery中对checkbox的各种“全选”或者“取消”功能实现(特别注意1.6+的一定不能使用attr来取属性了!用prop!)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html js 全选 反选 全不选源代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- WPF DataGrid CheckBox 多选 反选 全选
效果图 实现此效果的必要关键是 Style+DataTemplate 关键代码: <Window.Resources> <DataTemplate x:Key="Check ...
- js实现全选,反选,全不选
思路:1.获取元素.2.用for循环历遍数组,把checkbox的checked设置为true即实现全选,把checkbox的checked设置为false即实现不选.3.通过if判断,如果check ...
随机推荐
- Spring Boot 项目初始化
Spring Boot 项目创建 File->New->New Project->Spring Initializr 勾选 Web Spring Boot 版本选择稳定版,本文选择 ...
- JMeter常用菜单以及设置
如何清空View Results Tree 先选中目标view results tree,然后在菜单上选择Run-->Clear https://stackoverflow.com/questi ...
- C++变量的默认初始化规则
定义没有初始化式的变量时,系统有时候会帮我们初始化变量.系统如何初始化取决于变量的类型以及变量定义的位置. 内置类型变量是否自动初始化取决于变量定义的位置.函数体外定义的变量初始成0:函数体内定义的变 ...
- slot是标签的内容扩展,也就是说你用slot就可以在自定义组件时传递给组件内容,组件接收内容并输出
html 父页面<div id="app"> <register> <span slot="name">{{message. ...
- Linux---centos 配置网络
Linux配置网络,有两种方式,一种是通过图像化的界面来配置网络IP,另一种方式是通过命令行来配置IP 1.第一种方式通过图形化的界面来配置IP 1.0修改之前的IP地址 1.1点击图片中的那个 网络 ...
- Google advertiser api开发概述
对象.方法和服务 AdWords API 主要供 AdWords 的高级用户使用.如果您是 AdWords 新手,或需要复习 AdWords 基本概念,请查看 AdWords 基础知识页面. 对象层级 ...
- Twitter开发
开发文档:https://developer.twitter.com/ the Twitter Developer Account Application 示例:https://wptweetboos ...
- ZOJ 3632 ----dp+优先队列
上个礼拜学长讲了优先队列的说.... emmmmmm.... 看着题解敲了一题...先m下. #include<cstring> #include<algorithm> #in ...
- MySQL like用法
MySQL LIKE 语法 LIKE运算符用于WHERE表达式中,以搜索匹配字段中的指定内容,语法如下: WHERE column LIKE pattern WHERE column NOT LIKE ...
- _event
EventId 事件ID 请使用大于100的ID EventName 事件的名称,用于游戏中各种提示 NoticeText 事件开始时的弹窗内容 GossipText 功能宝石等菜单内容 Z ...