赞
踩
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>回复评论</title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
border: 0px;
}
.box{
width: 500px;
margin: 100px auto;
border: 1px solid #C0C0C0FF;
}
.box textarea{
/*作用是去掉文本输入框中右下角的标记*/
resize: none;
width: 300px;
/*作用是去掉外表框的蓝色边线*/
outline: none;
border: 1px solid #A0A0A0FF;
}
.box ul{
list-style: none;
}
.box ul li{
width: 300px;
margin-left: 70px;
border-bottom: 1px dotted #404040FF;
font: 15px/25px "微软雅黑";
}
.box ul li a{
font: 15px/25px "微软雅黑";
color: #A0A0A0FF;
text-decoration: none;
float: right;
}
.box input{
outline: none;
cursor: pointer;
}
.box ul li .time{
color: #FFD800FF;
}
</style>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
window.onload=function(){
var ul = document.createElement("ul");
$("di").appendChild(ul);
$("btn").onclick=function(){//点击按钮;
var txt1 = $("txt").value;//获取内容;
if(txt1 == "")
{
alert("评论为空,请重新输入!");
}
else{
txt1=txt1+"<span class='time'>"+new Date().toLocaleTimeString()+"</span>"+"<a href='javascript:void(0);'>删除</a>";//void(0)的作用是取消后续操作;
var first = ul.getElementsByTagName("li");
var newli = document.createElement("li");//创建一个li标签;
newli.innerHTML=txt1;//.innerText这个属性兼容性不好;
ul.insertBefore(newli, first[0]);//insertBefor(newchild,oldchild);
var del = ul.getElementsByTagName("a");//找到所有的a标签;
for (var i = 0; i < del.length; i++) {
del[i].onclick=function(){
ul.removeChild(this.parentNode);
}
}
}
}
}
</script>
</head>
<body>
<div class="box" id="di">
<span>发表评论:</span>
<textarea name="" id="txt" cols="30" rows="10"></textarea>
<input type="button" id="btn" value="发表评论"
</div>
</body>
</html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。