<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="main.css">
<script src="jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="parent">
<h4>留言内容:</h4>
<div id="box"></div>
<textarea id="text"></textarea><br>
<input id="btn" type="button" value="发表留言">
</div>
<script type="text/javascript">
var num = 1;
$('#btn').click(function(){
var html = '<p><span>用户' + num + '说:</span>' +
$('#text').val() + '</p>' + $('#box').html();
$('#box').html(html);
$('#text').val ('');
++num;
});
</script>
</body>
</html>
```css
* {
padding:0;
margin: 0;
}
body {
background-color: pink;
margin-top: 70px;
}
#parent {
width: 600px;
margin: 0 auto;
}
h4 {
line-height: 40px;
margin-bottom: 10px;
border-bottom: 1px solid #333;
}
p {
width: 100%;
margin-bottom: 25px;
line-height:24px;
}
#box {
width: 580px;
padding: 25px 10px 0;
border: 1px solid #ddd;
margin-bottom: 10px;
max-height: 450px;
overflow-y:auto;
word-break: break-all;
}
#text {
width: 100%;
height: 90px;
overflow: auto;
}
#btn {
width: 100%;
height: 50px;
}
2020-12-03
最新推荐文章于 2024-10-29 14:54:04 发布