摘要:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>模仿機(jī)器人的聊天</title></head><style type="text/css">button:hover{ 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>模仿機(jī)器人的聊天</title>
</head>
<style type="text/css">
button:hover{
background:red;
cursor: pointer;
}
</style>
<body>
<div style="width: 250px;height: 400px;border: 1px solid #ccc;margin: 15px auto 0px;background: #ccc;">
<div style="height: 76%;width: 100%;">
<ul>
</ul>
</div>
<div style="height: 13%;width: 220px;margin: 5px auto;background: seagreen;">
<textarea name="text" cols="20" rows="3"></textarea>
<button>發(fā)送</button>
</div>
</div>
<script type="text/javascript">
//獲取元素
//通過(guò)元素的name獲取元素
let textarea=document.getElementsByName('text').item(0);
//通過(guò)元素的TagName獲取元素
let button=document.getElementsByTagName('button').item(0);
let ul=document.getElementsByTagName('ul').item(0); //創(chuàng)建button的點(diǎn)擊事件
button.onclick=function(){
//創(chuàng)建li標(biāo)簽
let li=document.createElement('li');
//向li標(biāo)簽里面添加內(nèi)容
li.innerHTML=textarea.value;
//將內(nèi)容添加到列表項(xiàng)
ul.appendChild(li);
//清空textarea.value的值
textarea.value='';
}
</script>
</body>
</html>
批改老師:韋小寶批改時(shí)間:2018-12-18 11:56:28
老師總結(jié):頁(yè)面的確不太好看!這個(gè)你可以再做修改?。〔⒉皇呛軓?fù)雜??!