<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/vue.js"></script>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<div id="app" style="width: 1000px;margin: 0 auto;margin-top: 60px;">
<div class="form-group">
<label>手机号</label>
<input type="text" class="form-control" placeholder="(请输入手机号)" style="width: 500px;" v-model="mobile" />
</div>
<div class="form-group">
<label>邮箱</label>
<input type="text" class="form-control" placeholder="(请输入电子邮箱)" style="width: 500px;" v-model="email" />
</div>
<div class="form-group">
<label>真实姓名</label>
<input type="text" class="form-control" placeholder="(姓名必须是中文汉字)" style="width: 500px;"
v-model="realname" />
</div> <button type="button" class="btn btn-primary" @click="add">立即添加</button>
<p v-for="(v,k) in errors" style="margin: 0 auto;margin-top: 20px;color: red;font-size: 18px;">
{{v}}
</p> <div style="margin-top: 60px;">
<table class="table table-hover">
<th><input type="checkbox" v-model="isCheck" @click="check()"></th>
<th>编号</th>
<th>手机号</th>
<th>邮箱</th>
<th>真实姓名</th>
<th>操作</th>
<tr v-for="(v,k) in user">
<td><input type="checkbox" v-model="v.status"></td>
<td>{{v.id}}</td>
<td>{{v.mobile}}</td>
<td>{{v.email}}</td>
<td>{{v.realname}}</td>
<td><button class="btn btn-danger" @click="del(k)">删除</button></td>
</tr>
</table>
<button class="btn btn-danger" @click="checkAll()">全选</button>
<button class="btn btn-danger" @click="checkNo()">全不选</button>
<button class="btn btn-danger" @click="checkRev()">反选</button>
<button class="btn btn-danger" @click="checkDel()">批量删除</button>
</div>
</div>
</body>
</html> <script>
new Vue({
el: "#app",
data: {
mobile: "",
email: "",
realname: "",
errors: [],
isCheck: false,
user: [{
id: 1,
mobile: '18518393112',
email: '123131@qq.com',
realname: '邓超',
status: false
},
{
id: 2,
mobile: '18518393000',
email: '3322441@qq.com',
realname: '杨幂',
status: false
}
]
},
methods: {
//添加
add() {
if (this.checkForm()) {
//window.location.href = 'success.html'
var obj = {
id: this.user.length + 1,
mobile: this.mobile,
email: this.email,
realname: this.realname,
status: false
}
this.user.push(obj);
}
},
//表单验证
checkForm() {
this.errors = [];
if (this.mobile == '') {
this.errors.push('手机号不能为空');
return false;
}
var regMobile = /^1[35789]\d{9}$/;
if (!regMobile.test(this.mobile)) {
this.errors.push('手机号格式不正确');
return false;
}
if (this.email == '') {
this.errors.push('邮箱不能为空');
return false;
}
var regEmail = /^\w{6,30}@\w{2,6}\.+(com|cn)$/;
if (!regEmail.test(this.email)) {
this.errors.push('邮箱格式为空');
return false;
}
if (this.realname == '') {
this.errors.push('真实姓名不能为空');
return false;
}
var regRealname = /^[\u4e00-\u9fa5]{2,5}$/i;
if (!regRealname.test(this.realname)) {
this.errors.push('真实姓名格式不正确');
return false;
} if (this.errors.length == 0) {
return true;
} else {
return false;
}
},
//全选
checkAll() {
this.user.map(function(v, k) {
v.status = true;
});
},
//全不选
checkNo() {
this.user.map(function(v, k) {
v.status = false;
});
},
//反选
checkRev() {
this.user.map(function(v, k) {
v.status = !v.status;
});
},
//删除
del(k) {
this.user.splice(k, 1);
},
//批量删除
checkDel() {
var arr = [];
this.user.map(function(v, k) {
if (v.status == false) {
arr.push(v);
}
});
this.user = arr;
},
//点击复选框,全选/取消全选
check() {
if (this.isCheck == false) {
this.user.map(function(v, k) {
v.status = true;
});
} else {
this.user.map(function(v, k) {
v.status = false;
});
}
} }
});
</script>
sss

  

js-表格的更多相关文章

  1. js插件---JS表格组件BootstrapTable行内编辑解决方案x-editable

    js插件---JS表格组件BootstrapTable行内编辑解决方案x-editable 一.总结 一句话总结:bootstrap能够做为最火的框架,绝对不仅仅只有我看到的位置,它应该还有很多位置可 ...

  2. js 表格操作----添加删除

    js 表格操作----添加删除 书名:<input type="text" id="name"> 价格:<input type="t ...

  3. slickgrid 一个优秀的JS表格插件

    从熟悉JS以来,慢慢的喜欢上了这个门语言. 不自觉的,看了好多js的知识,可能也是因为做项目的原因吧. 这里稍微说下一个JS的grid插件 --slickgrid 了解这个插件也不是很多,稍微了解了下 ...

  4. JS表格分页(封装版)

    HTML代码: <html> <head> <meta charset='utf-8'> <script type="text/javascript ...

  5. 三.jquery.datatables.js表格编辑与删除

    1.为了使用如图效果(即将按钮放入行内http://www.datatables.net/examples/ajax/null_data_source.html) 采用了另一个数据格式 2.后台php ...

  6. JS表格分页组件:fupage的设计思路和详细使用方法(未来考虑开源,争取在2015年)

    一.背景         之前在秒针工作的时候,某js高级project师写了非常多自己的组件.当中一套是分页组件.叫做st-grid. 只是在我看来,bug太多.我常常给他反馈bug,我也不清楚为啥 ...

  7. js表格隔行换色和hover效果

    <!--js效果--> <script src="js/jquery.min.js" language="javascript">< ...

  8. JS表格分页组件:fupage的设计思路和具体用法(未来考虑开源,争取在2015年)

    一.背景         之前在秒针工作的时候,某js高级工程师写了很多自己的组件,其中一套是分页组件,叫做st-grid.不过在我看来,bug太多,我经常给他反馈bug,我也不清楚为啥别人没有发现. ...

  9. JS表格排序

    var employees = [] employees[0] = { name: "George", age: 32, retiredate: "March 12, 2 ...

  10. js 表格操作(兼容模式

    用insertRow,insertRow操作表格时,发现在谷歌浏览器中顺序和IE是反的 // 表格新增行 function addTableRow($id,$arr,$rowAttr){ var ta ...

随机推荐

  1. ARC084F - XorShift

    有两种解法,这里都放一下. 解法一 首先易知异或运算可以视作是 \(\mathbb{F}_2\) 意义下的每一位独立的加法. 因此我们可以考虑对于每个二进制数 \(s\) 构造一个多项式 \(F(x) ...

  2. linnux命令 - brctl和ifconfig

    1.安装brctl centos7.6安装使用 yum install bridge-utils ubuntu使用 apt-get install bridge-utils 什么是网桥 网桥是一种在链 ...

  3. errorC2471:cannot update program database vc90.pdb

    解决办法: C/C++ | General | Debug Information format | C7 Compatible (/Z7) C/C++ | Code Generation | Ena ...

  4. linux修改root用户登陆密码

    如果不是以root用户登录的,请先切换到root用户下, 执行命令:su root 然后按提示输入root用户的密码. 英文系统: [root@localhost ~]# passwd Changin ...

  5. Block基本概念

    1.什么是Block Block是iOS中一种比较特殊的数据类型 Block是苹果官方特别推荐使用的数据类型, 应用场景比较广泛 动画 多线程 集合遍历 网络请求回调 Block的作用 用来保存某一段 ...

  6. 动画移动scrollview内容

    #pragma mark - 按钮的点击 - (IBAction)top { /* [UIView animateWithDuration:2.0 animations:^{ // CGPoint o ...

  7. Java线程--Atomic原子类使用

    原创:转载需注明原创地址 https://www.cnblogs.com/fanerwei222/p/11871241.html Java线程--Atomic原子类使用 package concurr ...

  8. python基础语法_9-1闭包 装饰器补充

    1.闭包的概念 closure:内部函数中对enclosing作用域的变量进行引用,外部函数返回内部函数名   2.函数实质与属性 函数是一个对象:在内存中有一个存储空间 函数执行完成后内部变量回收: ...

  9. 读写分离&分库分表学习笔记

    读写分离 何为读写分离? 见名思意,根据读写分离的名字,我们就可以知道:读写分离主要是为了将对数据库的读写操作分散到不同的数据库节点上. 这样的话,就能够小幅提升写性能,大幅提升读性能. 我简单画了一 ...

  10. 从零开始, 开发一个 Web Office 套件(4):新的问题—— z-index

    <从零开始, 开发一个 Web Office 套件>系列博客目录 这是一个系列博客, 最终目的是要做一个基于HTML Canvas 的, 类似于微软 Office 的 Web Office ...