js

仿微博发表评论

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>你想对楼主说点什么 <span>你最多可输入30个字符</span></p>
<input type="text" name="" placeholder="请输入你想要说的内容">
<button>发表</button>
</div>
</div>

script

把图片做成随机数

var btn=document.querySelector('.content>button');
btn.onclick=function(){
var inputVal=document.querySelector('.content>input').value;
//动态创建元素:
//动态创建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);
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 现金流量是指企业一定时期的现金和现金等价物的流入和流出的数量,可以看出公司的存活能力,也就是“比气长”。 现金流量...
    画廊先生阅读 129评论 0 1
  • 文/图/007同学 像是冥冥之中的安排,十年后,我与北京不期而遇。 灰色的天空、闷热的天气、躁动的人流,初到北京的...
    007同学阅读 497评论 1 11
  • 视觉还原画面 只有你可以完整地还原画面,别人才能有画面感,也才能设身处地体会到你当时的心境。 生活中如何用眼睛搜集...
    镜鱼阅读 831评论 0 11
  • 题目 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 示例 1: 输入:...
    zhyee_yan阅读 817评论 0 0
  • nginx源码安装 nginx命令 nginx命令添加到环境变量中 nginx配置项 nginx 日志管理 ngi...
    love_program阅读 240评论 0 0