jQuery實(shí)現(xiàn)簡易聊天框
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)簡易聊天框的具體代碼,供大家參考,具體內(nèi)容如下
效果:
CSS代碼:
body{ margin: 0; } .kuan{ height:550px; width: 650px; background-color: #ccc; margin: 80px auto; } .header{ width: 100%; height: 35px; background-color: #00f; } .chatBody{ width: 100%; height: 70%; overflow:auto; } .footer{ width: 100%; height: 20%; } h2{ margin-bottom: 0; text-align: center; } .send{ background-color: green; width: 50px; } .btn{ text-align: right; } .btn span{ display: inline-block; padding: 0 10px; height: 25px; overflow: hidden; color: #fff; border-radius: 5px; background-color: #069dd5; font-size: 12px; margin-right: 3px; cursor:pointer; } .chatText{ border: none; width: 100%; height: 50px; } #input{ margin-left: 200px; width: 100px; } .a{ background-color: green; border-radius: 5px; width: 200px; height: 100%; }
主代碼:
<div class = "kuan"> <div class = "header"> <h2>聊天室</h2> </div> <div class = "chatBody"></div> <div class = "footer"> <textarea class="chatText"></textarea> <div class="btn"><span>關(guān)閉(C)</span><span id="send">發(fā)送(S)</span></div> <input type = "text" id = "input"></input> <input type = "submit" value = "確定" id = "sure"></input> <select id = "demo"> <option value = ""></option> </select> </div> </div>
jQuery代碼:
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script> <script type="text/javascript"> $("#demo").change(function(){ $("#input").val($(this).val());//將下拉框里的內(nèi)容放到文本框里 }); $(document).ready(function(){ $("#send").click(function(){ var $nei = $("textarea").val(); var $n = $("#input").val(); if($nei.length==""){ alert("你沒寫東西啊"); }else{ var $currentstr=$(".chatBody").append("<div>" + $n + ":" + "<p>" + $nei + "</p></div>"); $(".chatBody p").addClass("a");//消息框顏色 $("textarea").val("");//發(fā)送框消息消失 } }); }); </script>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于JQuery的簡單實(shí)現(xiàn)折疊菜單代碼
利用JQUERY簡單的實(shí)現(xiàn)功能菜單的折疊效果。本人初學(xué),寫后臺(tái)稍多一點(diǎn),很少寫前臺(tái)的效果。還請(qǐng)大蝦們多多指教。2010-09-09jQuery實(shí)現(xiàn)手風(fēng)琴效果(蒙版)
這篇文章主要介紹了jQuery實(shí)現(xiàn)手風(fēng)琴效果,附帶蒙版特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01jQuery中$this和$(this)的區(qū)別介紹(一看就懂)
這篇文章主要介紹了jQuery中$this和$(this)的區(qū)別介紹(一看就懂),本文用簡潔的語言講解了它們之間的區(qū)別,并給出了一個(gè)例子來說明,需要的朋友可以參考下2015-07-07jquery mobile實(shí)現(xiàn)撥打電話功能的幾種方法
在做一個(gè)便民服務(wù)電話,用到移動(dòng)web中列出的電話,點(diǎn)擊需要實(shí)現(xiàn)調(diào)用通訊錄,撥打電話功能,有需要的朋友可以參考一下2013-08-08Jquery 跨域訪問 Lightswitch OData Service的方法
修改lightswitch .server project web.config。添加如下內(nèi)容就可以實(shí)現(xiàn)對(duì)ApplicationData.svc/跨域訪問2013-09-09jQuery學(xué)習(xí)筆記之jQuery的動(dòng)畫
jQuery學(xué)習(xí)筆記之jQuery的動(dòng)畫,需要的朋友可以參考下。2010-12-12關(guān)于動(dòng)態(tài)生成dom綁定事件失效的原因及解決方法
下面小編就為大家?guī)硪黄P(guān)于動(dòng)態(tài)生成dom綁定事件失效的原因及解決方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08