JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了基于JavaScript实现评论框展开和隐藏功能大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

1.效果图如下所示,

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

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

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

number"> 493 条评论
知乎用户
2017.10.01 21:32:30
Mary btn-comment btn-sm">评论
知乎用户
2017.10.01 21:32:30
Mary btn-comment btn-sm">评论
知乎用户
2017.10.01 21:32:30
Mary btn-comment btn-sm">评论
知乎用户
2017.10.01 21:32:30
Mary btn-sm btn-comment">评论
你的评论">

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

{ 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控制对应评论按钮事件。

$(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"); }); });

总结

以上所述是小编给大家介绍的基于JavaScript实现评论框展开和隐藏功能。菜鸟教程 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得菜鸟教程不错,可分享给好友!感谢支持。

大佬总结

以上是大佬教程为你收集整理的基于JavaScript实现评论框展开和隐藏功能全部内容,希望文章能够帮你解决基于JavaScript实现评论框展开和隐藏功能所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:js展开隐藏
猜你在找的JavaScript相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap