分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

js对象注册清除

发布时间:2023-09-06 01:22责任编辑:彭小芳关键词:js

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.showTable{
border: 1px solid aquamarine;
width: 500px;
}

</style>
</head>
<script>
var peopArry=new Array();
var peopIndex=0;
function register(){
var peop=new Object();
peop.name=document.getElementById("name").value;
peop.age=document.getElementById("age").value;
peopArry[peopIndex]=peop;
peopIndex++;

}
function show(){

var peopData=document.getElementById("peopTbody");
var trData="<tr><td>"+peopArry[peopIndex-1].name+"</td><td>"+peopArry[peopIndex-1].age+"</td></tr>";
peopData.innerHTML=peopData.innerHTML+trData;
}
function clear(){
peopArry.splice(0,peopArry.length);
show();
}
function clearScr(){
var surData=document.getElementById("peopTbody");
surData.innerHTML="";
}
</script>
<body>
<table>
<div >
<table >
姓名:<input type="text" id="name"/>
年龄:<input type="text" id="age"/>
<input id="register" type="button" value="注册" onclick="register()"/>
<input id="show" type="button" value="显示" onclick="show()"/>
<input id="clear" type="button" value="清空" onclick="clear()"/>
<input id="clearScr" type="button" value="清屏" onclick="clearScr()"/>
</table>
</div>
<hr />
<div ?>
<table class="showTable" id="showTable" border="1">
<thead align="center" >
<tr>
<th >姓名</th><th >年龄</th>
</tr>
</thead>
<tbody id="peopTbody">

</tbody>
</table>
</div>
</body>
</html>

缺陷:清除数组中的元素后按显示按钮仍会显示注册信息。

js对象注册清除

原文地址:http://www.cnblogs.com/zshibo/p/7783421.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved