使用appendChild()和createElement()方法实现留言板
来源:互联网 发布:阿里云备案转入 编辑:程序博客网 时间:2024/05/20 06:23
<!doctype html>
<html><head>
<style>
#section1{
width:480px;
height:260px;
border:1px solid;
}
#liu{
width:480px;
}
.ti{
font-size:15px;
font-style:bold;
width:476px;
}
.con{
font-size:10px;
width:476px;
}
.zz{
border:1px solid;
}
</style>
<script>
function add(){
var ti = document.getElementById("tit");
var con = document.getElementById("in");
if(ti.value==""||con.value==""){
return;
}
var liu = document.getElementById("liu");
var p1=document.createElement("P");//新建一个P元素
var p2=document.createElement("P");
var p4=document.createElement("P");
var p3=document.createElement("SECTION");//新建一个section元素
p3.className="zz";//设置元素的class属性
p1.innerHTML= ti.value;//设置p元素的显示内容
p1.className="ti";
p2.innerHTML="    "+con.value;
p2.className="con";
p3.appendChild(p1);//添加节点,将新建的节点添加到已有的节点中就可在网页上显示出来
p3.appendChild(p2);
liu.appendChild(p3);
liu.appendChild(p4);
ti.value="";
con.value="";
}
function del(){
var ti = document.getElementById("tit");
var con = document.getElementById("in");
ti.value="";
con.value="";
}
</script>
<meta charset="UTF-8">
</head>
<body>
<h2 id="ti">留言板</h2>
<div id="liu">
</div>
<section id="section1">
<br>
<span>留言标题:</span><input type="text" id="tit"><br><br>
留言内容:<textarea id="in" placeholder="请留言" cols="50" rows="10"></textarea>
<br><br>            <button onclick="add()">提交</button>  <button onclick="del()">清除</button>
</section>
</body>
</html>
阅读全文
0 0
- 使用appendChild()和createElement()方法实现留言板
- DOM操作(createElement()、createTextNode()、appendChild())
- createElement appendChild
- createElement、appendChild、removeChild等方法的应用
- JS 中的appendChild和createElement的用法
- 关于createElement、appendChild和insertBefore的用法
- 通过createElement(),createTextNode),appendChild()方法来显示文字
- createElement cloneNode appendChild applyElement
- js createElement appendChild createTextNode用法
- insertBefore()方法 和 appendChild() 方法
- IE和Firefox都兼容的document.createElement方法实现
- React.createElement方法使用详解
- 创建节点 createElement appendChild document.createTextNode
- appendChild、removeChild、insertBefore、createElement、cloneNode的区别;
- js中创建元素createElement\createTextNode\appendChild
- document.createElement()
- 简化document.createElement("div")动态生成层方法 (转)
- 动态生成Html元素实现Post操作(createElement)
- 这是一个转型AI的励志故事,从非科班到拿下竞赛一等奖
- react native学习笔记17——存储篇(2)SQLite
- JVM类的初始化
- 加载网络图片
- 怎么在Android手机没root的情况下读取手机系统文件(比如数据库文件)
- 使用appendChild()和createElement()方法实现留言板
- 慕课网——JS实现贪吃蛇游戏——01(蛇出洞喽~)
- GCD HDU
- 100+经典Java面试题及答案解析
- Cookie,session记录上次访问时间
- 如何用js判断平年瑞年
- 前后端分离2:使用axios做网络请求
- 很久没有更新博客 今天博客来一波更新
- springmvc静态资源处理