這篇文章給大家分享的是有關(guān)如何基于JavaScript實(shí)現(xiàn)評(píng)論框展開和隱藏功能的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到長(zhǎng)寧網(wǎng)站設(shè)計(jì)與長(zhǎng)寧網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)制作、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋長(zhǎng)寧地區(qū)。1.效果圖如下所示,
點(diǎn)擊評(píng)論會(huì)在對(duì)應(yīng)的評(píng)論區(qū)域展開評(píng)論輸入框,點(diǎn)擊取消會(huì)取消對(duì)應(yīng)的評(píng)論輸入框
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>條評(píng)論</span> </div> <div class="comment-sort"> 切換為時(shí)間排序 </div> </div> <div class="comment-content"> <div class="com-users"> <div class="comment-user"> <span>知乎用戶</span> <div class="comment-user-content"> 這個(gè)爬蟲真的好強(qiáng)大! </div> </div> <div class="comment-time"> <div>2017.10.01 21:32:30</div> <button class="btn btn-primary btn-sm btn-reply">回復(fù)</button> </div> </div> <div class="user-reply"> <duv class="reply-in"> <input type="text" value="" name="" placeholder="請(qǐng)輸入評(píng)論內(nèi)容" /> </duv> <div class="reply-buttons"> <button type="button" class="btn btn-primary btn-comment btn-sm">評(píng)論</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"> 這個(gè)爬蟲真的好強(qiáng)大! </div> </div> <div class="comment-time"> <div>2017.10.01 21:32:30</div> <button class="btn btn-primary btn-sm btn-reply">回復(fù)</button> </div> </div> <div class="user-reply"> <duv class="reply-in"> <input type="text" value="" name="" placeholder="請(qǐng)輸入評(píng)論內(nèi)容" /> </duv> <div class="reply-buttons"> <button type="button" class="btn btn-primary btn-comment btn-sm">評(píng)論</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"> 這個(gè)爬蟲真的好強(qiáng)大! </div> </div> <div class="comment-time"> <div>2017.10.01 21:32:30</div> <button class="btn btn-primary btn-sm btn-reply">回復(fù)</button> </div> </div> <div class="user-reply"> <duv class="reply-in"> <input type="text" value="" name="" placeholder="請(qǐng)輸入評(píng)論內(nèi)容" /> </duv> <div class="reply-buttons"> <button type="button" class="btn btn-primary btn-comment btn-sm">評(píng)論</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"> 這個(gè)爬蟲真的好強(qiáng)大! </div> </div> <div class="comment-time"> <div>2017.10.01 21:32:30</div> <button class="btn btn-primary btn-sm btn-reply">回復(fù)</button> </div> </div> <div class="user-reply"> <duv class="reply-in"> <input type="text" value="" name="" placeholder="請(qǐng)輸入評(píng)論內(nèi)容" /> </duv> <div class="reply-buttons"> <button type="button" class="btn btn-primary btn-sm btn-comment">評(píng)論</button> <button type="button" class="btn btn-default btn-sm btn-cancel">取消</button> </div> </div> </div> <div class="comment-ipt"> <input type="text" placeholder="輸入你的評(píng)論"> <button type="submit" class="btn btn-sm btn-primary">評(píng)論</button> </div> </div> </div>
3.css樣式代碼,樣式無(wú)所謂,自己寫就可以。
.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控制對(duì)應(yīng)評(píng)論按鈕事件。
<script> $(document).ready(function() { $('.btn-reply').click(function() { // console.log($(this).index()); // 獲取回復(fù)按鈕集合,getElementByClassName; var m = document.getElementsByClassName("btn-reply"); var n = document.getElementsByClassName("user-reply"); console.log('回復(fù)按鈕集合' + m); // 獲取回復(fù)按鈕的索引 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>
感謝各位的閱讀!關(guān)于“如何基于JavaScript實(shí)現(xiàn)評(píng)論框展開和隱藏功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
本文標(biāo)題:如何基于JavaScript實(shí)現(xiàn)評(píng)論框展開和隱藏功能-創(chuàng)新互聯(lián)
當(dāng)前URL:http://jinyejixie.com/article14/ghgde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、自適應(yīng)網(wǎng)站、域名注冊(cè)、響應(yīng)式網(wǎng)站、定制網(wǎng)站、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容