相思资源网 Design By www.200059.com

1.效果图如下所示,

点击评论会在对应的评论区域展开评论输入框,点击取消会取消对应的评论输入框

基于JavaScript实现评论框展开和隐藏功能

2.html代码:需要引入jQuery.js

<div
class="nr-comment">
<div
class="nr-comment-con">
<div
class="nr-comment-nav">
<div
class="comment-number">
<span>493</span>
<span>条评论</span>
</div>
<div
class="comment-sort">
切换为时间排序
</div>
</div>
<div
class="comment-content">
<div
class="com-users">
<div
class="comment-user">
<span>知乎用户</span>
<div
class="comment-user-content">
这个爬虫真的好强大!
</div>
</div>
<div
class="comment-time">
<div>2017.10.01 21:32:30</div>
<button
class="btn btn-primary btn-sm btn-reply">回复</button>
</div>
</div>
<div
class="user-reply">
<duv
class="reply-in">
<input
type="text"
value=""
name=""
placeholder="请输入评论内容" />
</duv>
<div
class="reply-buttons">
<button
type="button"
class="btn btn-primary btn-comment btn-sm">评论</button>
<button
type="button"
class="btn btn-default btn-cancel btn-sm">取消</button>
</div>
</div>
</div>
<div
class="comment-content">
<div
class="com-users">
<div
class="comment-user">
<span>知乎用户</span>
<div
class="comment-user-content">
这个爬虫真的好强大!
</div>
</div>
<div
class="comment-time">
<div>2017.10.01 21:32:30</div>
<button
class="btn btn-primary btn-sm btn-reply">回复</button>
</div>
</div>
<div
class="user-reply">
<duv
class="reply-in">
<input
type="text"
value=""
name=""
placeholder="请输入评论内容" />
</duv>
<div
class="reply-buttons">
<button
type="button"
class="btn btn-primary btn-comment btn-sm">评论</button>
<button
type="button"
class="btn btn-default btn-cancel btn-sm">取消</button>
</div>
</div>
</div>
<div
class="comment-content">
<div
class="com-users">
<div
class="comment-user">
<span>知乎用户</span>
<div
class="comment-user-content">
这个爬虫真的好强大!
</div>
</div>
<div
class="comment-time">
<div>2017.10.01 21:32:30</div>
<button
class="btn btn-primary btn-sm btn-reply">回复</button>
</div>
</div>
<div
class="user-reply">
<duv
class="reply-in">
<input
type="text"
value=""
name=""
placeholder="请输入评论内容" />
</duv>
<div
class="reply-buttons">
<button
type="button"
class="btn btn-primary btn-comment btn-sm">评论</button>
<button
type="button"
class="btn btn-default btn-cancel btn-sm">取消</button>
</div>
</div>
</div>
<div
class="comment-content">
<div
class="com-users">
<div
class="comment-user">
<span>知乎用户</span>
<div
class="comment-user-content">
这个爬虫真的好强大!
</div>
</div>
<div
class="comment-time">
<div>2017.10.01 21:32:30</div>
<button
class="btn btn-primary btn-sm btn-reply">回复</button>
</div>
</div>
<div
class="user-reply">
<duv
class="reply-in">
<input
type="text"
value=""
name=""
placeholder="请输入评论内容" />
</duv>
<div
class="reply-buttons">
<button
type="button"
class="btn btn-primary btn-sm btn-comment">评论</button>
<button
type="button"
class="btn btn-default btn-sm btn-cancel">取消</button>
</div>
</div>
</div>
<div
class="comment-ipt">
<input
type="text"
placeholder="输入你的评论">
<button
type="submit"
class="btn btn-sm btn-primary">评论</button>
</div>
</div>
</div>

3.css样式代码,样式无所谓,自己写就可以。

.nr-comment {
width:
100%;
border-right:
1px 
solid #A9A9A9;
border-left:
1px 
solid #A9A9A9;
}
.nr-comment .nr-comment-con {
width:
100%;
}
.nr-comment .nr-comment-con .nr-comment-nav {
width:
100%;
height:
40px;
border-bottom:
1px 
solid #F5F5F6;
border-right:
1px 
solid #A9A9A9;
border-left:
1px 
solid #A9A9A9;
background-color:
#1E8CE0;
}
.nr-comment .nr-comment-con .nr-comment-nav .comment-number {
float:
left;
width:
85px;
height:
30px;
text-align:
center;
margin-top:
5px;
color:
white;
line-height:
2.3em;
}
.nr-comment .nr-comment-con .nr-comment-nav .comment-sort {
float:
right;
width:
110px;
height:
30px;
margin-top:
5px;
margin-right:
10px;
line-height:
2em;
color:
white;
}
.nr-comment .nr-comment-con .comment-content {
width:
100%;
margin-top:
10px;
border-bottom:
1px 
solid #a9a9a9;
}
.nr-comment .nr-comment-con .comment-content .com-users {
width:
100%;
min-height:
60px;
}
.nr-comment .nr-comment-con .comment-content .com-users .comment-user {
float:
left;
width:
500px;
height:
60px;
}
.nr-comment .nr-comment-con .comment-content .com-users .comment-user span {
color:
black;
margin-left:
10px;
}
.nr-comment .nr-comment-con .comment-content .com-users .comment-user .comment-user-content {
width:
90%;
height:
60px;
margin-left:
10px;
}
.nr-comment .nr-comment-con .comment-content .com-users .comment-time {
float:
right;
width:
190px;
height:
60px;
text-align:
center;
color:
#9CADC6;
font-size:
0.9em;
text-align:
right;
}
.nr-comment .nr-comment-con .comment-content .com-users .comment-time div {
margin-right:
15px;
}
.nr-comment .nr-comment-con .comment-content .com-users .comment-time .btn-reply {
margin-top:
5px;
border-radius:
4px;
border:
none;
background-color:
#1BB394;
color:
white;
margin-right:
15px;
}
.nr-comment .nr-comment-con .comment-content .user-reply {
display:
none;
width:
100%;
height:
50px;
}
.nr-comment .nr-comment-con .comment-content .user-reply .reply-in {
float:
left;
width:
85%;
height:
50px;
}
.nr-comment .nr-comment-con .comment-content .user-reply .reply-in input {
width:
100%;
height:
30px;
margin-top:
10px;
margin-left:
10px;
}
.nr-comment .nr-comment-con .comment-content .user-reply .reply-buttons {
float:
right;
margin-top:
10px;
}
.nr-comment .nr-comment-con .comment-content .user-reply .reply-buttons .btn-comment {
float:
right;
margin-right:
14px;
background-color:
#1BB394;
border:
none;
color:
white;
}
.nr-comment .nr-comment-con .comment-content .user-reply .reply-buttons .btn-cancel {
float:
right;
margin-right:
10px;
}
.nr-comment .nr-comment-con .comment-ipt {
width:
100%;
height:
40px;
border-bottom:
1px 
solid #A9A9A9;
margin-top:
10px;
}
.nr-comment .nr-comment-con .comment-ipt input {
display:
block;
width:
92%;
height:
30px;
float:
left;
font-size:
14px;
margin-left:
10px;
}
.nr-comment .nr-comment-con .comment-ipt button {
display:
block;
float:
right;
background-color:
#1BB394;
color:
white;
margin-right:
13px;
border:
none;
}

4.js控制对应评论按钮事件。

<script>
$(document).ready(function()
 {
$('.btn-reply').click(function()
 {
// console.log($(this).index());
// 获取回复按钮集合,getElementByClassName;
var m
= document.getElementsByClassName("btn-reply");
var n
= document.getElementsByClassName("user-reply");
console.log('回复按钮集合'
+ m);
// 获取回复按钮的索引
var index
= $(".btn-reply").index($(this));
console.log(index);
$(".user-reply").eq(index).css("display",
"block");
});
$('.btn-cancel').click(function()
 {
var m
= document.getElementsByClassName("btn-reply");
var n
= document.getElementsByClassName("user-reply");
var index
= $(".btn-cancel").index($(this));
console.log(index);
$(".user-reply").eq(index).css("display",
"none");
});
});
</script>

总结

以上所述是小编给大家介绍的基于JavaScript实现评论框展开和隐藏功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

标签:
js评论框,js,展开,隐藏

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“基于JavaScript实现评论框展开和隐藏功能”

暂无基于JavaScript实现评论框展开和隐藏功能的评论...

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。