用DOM相关方法创建的留言板

 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
#ul1 {margin:0; padding:0;}
#ul1 li {list-style:none; width:300px; background:#CCC; border:1px solid #999; position:relative;}
#ul1 li h2 {display:inline-block;}
#ul1 li p {display:inline-block;}
#ul1 li a {position:absolute; right:4px; bottom:4px;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function (){
var oName=document.getElementById('name');
var oContent=document.getElementById('content');
var oUl=document.getElementById('ul1');
var oBtn=document.getElementById('btn1');
var aLi=oUl.getElementsByTagName('li');
var oLi=null; oBtn.onclick=function (){
oLi=document.createElement('li');
var oH2=document.createElement('h2');
var oP=document.createElement('p');
var oA=document.createElement('a'); oH2.innerHTML=oName.value+':';
oP.innerHTML=oContent.value;
oA.innerHTML='删除';
oA.href='javascript:;';
oA.onclick=function (){
oUl.removeChild(this.parentNode);
}; oLi.appendChild(oH2);
oLi.appendChild(oP);
oLi.appendChild(oA); if(aLi.length>0){
oUl.insertBefore(oLi, aLi[0]); //确保新添加的在最前面
}
else{
oUl.appendChild(oLi);
}
};
};
</script>
</head>
<body>
姓名:<input id="name" type="text" /><br />
内容:<textarea id="content" rows="5" cols="40"></textarea><br />
<input id="btn1" type="button" value="留言" />
<ul id="ul1">
</ul>
</body>
</html>

最新文章

  1. CSS笔记之伪类与伪元素
  2. Java图形化用户界面(GUI)笔记(一)介绍
  3. 在ubuntu 16.04系统环境中搭建NAS(samba/iscsi/nfs)
  4. Gridview LookupEdit gridLookUpEdit z
  5. H5 视频直播相关技术
  6. selenim之ActionChains(一)
  7. git 和github使用
  8. Jmeter实例(二)简单的性能测试场景
  9. ABP+AdminLTE+Bootstrap Table权限管理系统第三节--abp分层体系,实体相关及ABP模块系统
  10. unity3d 九宫密码锁
  11. TCP:WireShark分析,序列号Seq和确认号Ack
  12. 用Jetty 9.1运行Java WebSockets微服务
  13. c# 文字首字母
  14. UNIX网络编程 第4章 基本TCP套接字编程
  15. 最简单的WebService
  16. 去掉第一次ssh连接的yes问题
  17. 使用AddressSanitizer做内存分析(一)——入门篇
  18. poj 2104(线段树)
  19. hdoj1005--Number Sequence
  20. 微软“小冰”识狗与人工神经网络(I)

热门文章

  1. android开发设置dialog的高宽
  2. 谈谈php中上传文件的处理
  3. nginx 如何显示真实ip
  4. mysql Host ‘XXXXXX’ is blocked because of many connection errors
  5. stdint.h 文件 int8_t uint8_t int16_t uint16_t
  6. PHP读取xml之cdata讲解
  7. Relearning PHP (2) – php 的浮点数float
  8. hdu 2582 f(n) 数学
  9. TopCoder 603 div1 &amp; div2
  10. hdu1116