摘要:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>实战热身,聊天信息框的输出</title> <style> body{margin:0;padding:20px;} ul&nbs
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>实战热身,聊天信息框的输出</title>
<style>
body{margin:0;padding:20px;}
ul {margin:0;padding:0;}
li{list-style: none;}
.main{margin:0 auto;border:1px solid #999;border-radius:8px;text-align: center;width:300px;min-height:600px;display: flex;flex-direction: column;justify-content: flex-end;padding:20px;background-color:#fffff0;box-shadow: 1px 1px 10px 2px #aaa;}
button{background-color:#009F95;border-radius: 5px;border:1px solid #999;padding:5px 10px;color:#fff;outline: none;font-weight: 600;cursor: pointer;}
button:active{background-color:yellow;color:#000;}
input {
height: 28px;
box-sizing: border-box;
text-align: center;
border-radius: 5px;
outline: none;
border: 1px solid #999;
width: 220px;
}
</style>
</head>
<body>
<div class="main">
<ul></ul>
<div>
<input type="text" name="msg">
<button>发送</button>
</div>
</div>
<script type="text/javascript">
//获取元素
let input = document.getElementsByName('msg')[0];
let btn = document.getElementsByTagName('button')[0];
let ul = document.getElementsByTagName('ul').item(0);
//点击按钮
btn.onclick = function(){
//如果为空,则返回
if(input.value == '')return;
let li = document.createElement('li');
li.innerHTML = input.value;
ul.appendChild(li);
input.value = '';
}
</script>
</body>
</html>
批改老师:韦小宝批改时间:2019-02-01 09:47:27
老师总结:写的很不错 这种案例又简单又有意思,没事可以多练习练习!