您的位置:首页 > 其它

8.一个能自动提交和删除的表单

2017-04-09 21:58 253 查看
<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
onload = function () {
var j = document.getElementsByTagName("input");

var oList = document.getElementById("list");
var a = document.getElementsByTagName("a");

j[3].onclick = function () {
var newtr = document.createElement("tr");
for(var i = 0;i<j.length-1;i++){
var newtd = document.createElement("td");
newtd.innerHTML = j[i].value;
newtr.appendChild(newtd);
}

var newtd4 = document.createElement("td");
var a = document.createElement("a");
a.innerHTML = "删除";
a.href = "#";
newtd4.appendChild(a);
newtr.appendChild(newtd4);

oList.lastChild.appendChild(newtr);
del();
}
function del(){

for(var i = 1;i<a.length;i++){
a[i].index = i;

a[i].onclick = function (){
oList.lastChild.removeChild(this.parentNode.parentNode);
}
}
}
 

}
</script>
<style>
div{
height: 500px;
width: 500px;
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input{
width: 200px;
height: 50px;
}
</style>

</head>

<body>
<div>
<input type="text" value="请输入您的姓名" /> <br />
<input type="text" value="请输入您的ID" /><br />
<input type="text" value="请输入您的电话" /><br />

<input type="button" value="提交" />

<table border="" cellspacing="" cellpadding="" id="list">
<tr>
<th>ID</th>
<th>Name</th>
<th>phone</th>
<th>op</th>
</tr>
<tr>
<td>王定坤</td>
<td>3</td>
<td>18888888</td>
<td>
<a href="#">删除</a>
</td>
</tr>
</table>
</div>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐