H5使用js追加表格进行操作
来源:互联网 发布:linux 看目录本身权限 编辑:程序博客网 时间:2024/05/16 12:35
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
.table td {
border: 1px solid black;
width: 100px;
background-color: white;
}
.table{
background-color: #000000;
}
</style>
</head>
<body>
<table>
<tr>
<td>账号</td>
<td><input type="text" class="user" id="user"/><span id="span_user"></span></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" class="pwd" id="pwd"/><span id="span_pwd"></span></td>
</tr>
<tr>
<td colspan="2"><input type="button" value="添加" onclick="add()"/></td>
</tr>
</table>
<br />
<br />
<hr />
<br />
<button onclick="del(0)">批量删除</button><button onclick="sel()">全选</button><button onclick="boo()">反选</button>
<table class="table" id="table" cellpadding="1px" cellspacing="0px">
<tr>
<td></td>
<td>用户名</td>
<td>密码</td>
<td>操作</td>
</tr>
</table>
<script>
function add(){
var user = document.getElementById("user").value;
var pwd = document.getElementById("pwd").value;
var table = document.getElementById("table");
if(haha(user,pwd)){
var td_user = document.createElement("td");
var td_pwd = document.createElement("td");
var td_ck = document.createElement("td");
var td_delete = document.createElement("td");
td_ck.innerHTML="<input name='che' type='checkbox'/>"
td_user.innerHTML=user;
td_pwd.innerHTML=pwd;
td_delete.innerHTML="<a onclick='del2(this)'>删除</a>"
var tr = document.createElement("tr");
tr.appendChild(td_ck);
tr.appendChild(td_user);
tr.appendChild(td_pwd);
tr.appendChild(td_delete);
table.appendChild(tr)
}
}
function haha(user,pwd){
var span_user = document.getElementById("span_user");
var span_pwd = document.getElementById("span_pwd");
if(user==""||user==null){
span_user.style.color="red"
span_user.innerHTML="账号不能为空"
return false;
}else{
span_user.innerHTML="";
}
if(pwd==""||pwd.length>6){
span_pwd.style.color="red"
span_pwd.innerHTML="密码不能为空并且要小于6位"
return false;
}else{
span_pwd.innerHTML="";
}
return true;
}
function sel(){
var ches = document.getElementsByName("che");
for (i=0;i<ches.length;i++) {
ches[i].checked=true
}
}
function boo(){
var ches = document.getElementsByName("che");
for (i=0;i<ches.length;i++) {
ches[i].checked=!ches[i].checked;
}
}
function del(suo){
var q=suo;
var ches = document.getElementsByName("che");
for (i=0;i<ches.length;i++) {
if(ches[i].checked){
ches[i].parentNode.parentNode.remove();
q++;
del(q);
}
}
if(q==0){
alert("请至少选中一行");
}
}
function del2(aa){
aa.parentNode.parentNode.remove();
}
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
.table td {
border: 1px solid black;
width: 100px;
background-color: white;
}
.table{
background-color: #000000;
}
</style>
</head>
<body>
<table>
<tr>
<td>账号</td>
<td><input type="text" class="user" id="user"/><span id="span_user"></span></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" class="pwd" id="pwd"/><span id="span_pwd"></span></td>
</tr>
<tr>
<td colspan="2"><input type="button" value="添加" onclick="add()"/></td>
</tr>
</table>
<br />
<br />
<hr />
<br />
<button onclick="del(0)">批量删除</button><button onclick="sel()">全选</button><button onclick="boo()">反选</button>
<table class="table" id="table" cellpadding="1px" cellspacing="0px">
<tr>
<td></td>
<td>用户名</td>
<td>密码</td>
<td>操作</td>
</tr>
</table>
<script>
function add(){
var user = document.getElementById("user").value;
var pwd = document.getElementById("pwd").value;
var table = document.getElementById("table");
if(haha(user,pwd)){
var td_user = document.createElement("td");
var td_pwd = document.createElement("td");
var td_ck = document.createElement("td");
var td_delete = document.createElement("td");
td_ck.innerHTML="<input name='che' type='checkbox'/>"
td_user.innerHTML=user;
td_pwd.innerHTML=pwd;
td_delete.innerHTML="<a onclick='del2(this)'>删除</a>"
var tr = document.createElement("tr");
tr.appendChild(td_ck);
tr.appendChild(td_user);
tr.appendChild(td_pwd);
tr.appendChild(td_delete);
table.appendChild(tr)
}
}
function haha(user,pwd){
var span_user = document.getElementById("span_user");
var span_pwd = document.getElementById("span_pwd");
if(user==""||user==null){
span_user.style.color="red"
span_user.innerHTML="账号不能为空"
return false;
}else{
span_user.innerHTML="";
}
if(pwd==""||pwd.length>6){
span_pwd.style.color="red"
span_pwd.innerHTML="密码不能为空并且要小于6位"
return false;
}else{
span_pwd.innerHTML="";
}
return true;
}
function sel(){
var ches = document.getElementsByName("che");
for (i=0;i<ches.length;i++) {
ches[i].checked=true
}
}
function boo(){
var ches = document.getElementsByName("che");
for (i=0;i<ches.length;i++) {
ches[i].checked=!ches[i].checked;
}
}
function del(suo){
var q=suo;
var ches = document.getElementsByName("che");
for (i=0;i<ches.length;i++) {
if(ches[i].checked){
ches[i].parentNode.parentNode.remove();
q++;
del(q);
}
}
if(q==0){
alert("请至少选中一行");
}
}
function del2(aa){
aa.parentNode.parentNode.remove();
}
</script>
</body>
</html>
阅读全文
0 0
- H5使用js追加表格进行操作
- js动态表格追加行
- js 对表格进行各种操作
- js 对表格进行各种操作
- Angular JS 之对表格进行操作
- 使用js对表格进行汇总
- 使用jq对表格数据进行操作
- 使用Js实现网页表格操作
- 利用js事件进行简单的表格操作
- 【转载】js 对表格进行各种操作(转)
- 使用HBuilder操作H5
- 【前端H5】bootstrap-table表格插件使用js设置高度及高度自适应
- [python]使用xlrd对Excel表格进行读写操作
- JAVA使用jxl.jar对excel表格进行操作处理
- [python]使用xlrd对Excel表格进行读写操作
- h5 video 追加
- js 表格操作
- JS操作表格
- WinEdt调出公式编辑器
- FCC--Pig Latin(儿童黑话)
- C语言使用动态链接库静态链接库
- 关于java static 关键字
- oracle delete from和 truncate区别
- H5使用js追加表格进行操作
- leetcode 669. Trim a Binary Search Tree修剪二叉搜索树
- Retrofit上传多张图片
- 转载 Linux内存管理(最透彻的一篇)
- SSM整合百度富文本编辑器ueditor二
- 一些开源项目汇总地址
- AndroidStudio3.0开发调试安卓NDK的C++代码
- yii2.0框架深入解析学习
- Android浏览器开源项目