首页 技术 正文
技术 2022年11月11日
0 收藏 404 点赞 2,358 浏览 1298 个字
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>js练习</title>
<style type="text/css">
#ull{
padding:0px;
margin: 0px;
}
#ull li{
list-style:none;
background-color: #ccc;
width:auto;
border:1px solid #999;
position:relative;
}
#ull li h2{
display:inline-block;
}
#ull li p{
display:inline-block;
}
#ull li a{
position:absolute;
text-decoration: none;
color:red;
right:5px;
bottom:5px;
}
#content{
width:300px;
height:100px;
}
</style>
<script type="text/javascript">
window.onload = function() {
var oname = document.getElementById('name');
var ocontent = document.getElementById('content');
var oul = document.getElementById('ull');
var obtn = document.getElementById('btn');
var lli = oul.getElementsByTagName('li');
obtn.onclick = function(){
oli = document.createElement('li');
oh2 = document.createElement('h2');
op = document.createElement('p');
oa = document.createElement('a');
oa.innerHTML="删除";
oa.href = "javascript:;";
oa.onclick = function(){
oul.removeChild(this.parentNode);
} oh2.innerHTML = oname.value + ':';
op.innerHTML = ocontent.value; oli.appendChild(oh2);
oli.appendChild(op);
oli.appendChild(oa);
if(lli.length > 0){
oul.insertBefore(oli,lli[0]);
}
else{
oul.appendChild(oli);
}
} }
</script>
</head>
<body>
姓名:<input type="text" id="name"><br>
留言:<textarea cols="20" rows="3" wrap = "hard" id="content"></textarea><br>
<button id="btn">添加</button>
<ul id="ull">
</ul>
</body>
</html>

这是一个利用DOM制作的一个简易留言板

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848