仿微博發(fā)表評(píng)論
css樣式
{
margin:0;
padding:0;
}
a{
text-decoration: none;
}
input{
border:0;
}
li{
list-style: none;
}
.container{
width:800px;
margin:0 auto;
/border:1px solid #000;/
padding:20px;
}
input{
border:1px solid #666;
width:100%;
height:100px;
padding-left:10px;
}
.content>p{
font-weight: bold;
font-size: 20px;
padding:10px;
}
.content>p>span{
font-weight: normal;
font-size:14px;
margin-left:400px;
}
.content>button{
width:70px;
height:40px;
line-height: 40px;
background: #e4393c;
border-radius: 5px;
border:0;
font-size: 16px;
font-weight: bold;
color:#fff;
margin-top:10px;
margin-left:90%;
}
.main{
width:100%;
border:1px solid #000;
overflow: hidden;
border-radius: 20px;
margin-top:20px;
padding:0 10px;
}
.main>img,.main>p{
float:left;
}
.main>img{
width:100px;
height:100px;
}
.main>p{
width:500px;
height:100px;
line-height: 100px;
padding-left:50px;
/border:1px solid #000;*/
}
.main>button{
width:70px;
height:40px;
line-height: 40px;
background: #e4393c;
border-radius: 5px;
border:0;
font-size: 16px;
font-weight: bold;
color:#fff;
float:right;
margin-top:30px;
}
<div class='container'>
<div class='content'>
<p>你想對(duì)樓主說(shuō)點(diǎn)什么 <span>你最多可輸入30個(gè)字符</span></p>
<input type="text" name="" placeholder="請(qǐng)輸入你想要說(shuō)的內(nèi)容">
<button>發(fā)表</button>
</div>
</div>
script
把圖片做成隨機(jī)數(shù)
var btn=document.querySelector('.content>button');
btn.onclick=function(){
var inputVal=document.querySelector('.content>input').value;
//動(dòng)態(tài)創(chuàng)建元素:
//動(dòng)態(tài)創(chuàng)建div
var div=document.createElement('div');
div.className='main';
var img=document.createElement('img');
var arr=['img/1.jpg','img/2.jpg','img/3.jpg'];
var num=Math.floor(Math.random()*3);
img.src=arr[num];
div.appendChild(img);
var p=document.createElement('p');
p.innerHTML=inputVal;
document.querySelector('.content>input').value='';
div.appendChild(p);
var button=document.createElement('button');
button.innerHTML='刪除';
button.onclick=function remov(){
this.parentElement.parentElement.removeChild(this.parentElement);
}
div.appendChild(button);
document.querySelector('.container').appendChild(div);
}