欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery編寫QQ簡(jiǎn)易聊天框

 更新時(shí)間:2020年08月27日 11:16:37   作者:左手寫愛  
這篇文章主要為大家詳細(xì)介紹了jQuery編寫QQ簡(jiǎn)易聊天框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了jQuery編寫QQ簡(jiǎn)易聊天框的具體代碼,供大家參考,具體內(nèi)容如下

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title>QQ簡(jiǎn)易聊天框</title>
 <link rel="stylesheet" href="css/chat.css" >
 <style type="text/css">
 .chatBody ul li{ list-style-type:none;}
 .chatBody ul li img{ width:35px; height:33px; float:left;}
 .chatBody ul li h1{width:395px; text-indent:0px; margin-left:6px;float:left; font-size:15px; font-weight:normal;}
 .chatBody ul li p{width:385px; text-indent:5px; margin:0px 10px 0px 6px; border-radius:5px; height:30px; line-height:30px;font-size:14px; float:left; background:#CCC}
 </style>
 <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
 <script type="text/javascript">
 $(document).ready(function() {
     //點(diǎn)擊發(fā)送
    $("#send").click(function(){
  qqQend();
 }); 
 $(document).keydown(function(event){
 if(event.keyCode=="13"){//按下回車鍵
 qqQend();
 }
 });
 
 function qqQend(){
 var $text=$(".chatText").val();//獲取輸入框內(nèi)容
 if($text==""){
 alert("請(qǐng)輸入聊天內(nèi)容");
 }else{ 
 var tou=new Array(1,2,3);
 var names=new Array("時(shí)尚依人","松松","六月奇跡");
 var r=parseInt(Math.random()*tou.length);
 var touPath="images/head0"+tou[r]+".jpg";//頭像路徑
 $name=names[r];//人物昵稱  
 //1、創(chuàng)建li
 $li=$("<li></li>");
 //2、創(chuàng)建img
 var $img=$("<img src="+touPath+" />");
 $li.append($img);
 //3、創(chuàng)建h1
 var $h1=("<h1>"+$name+"</h1>");
 $li.append($h1);
 //4、創(chuàng)建p
 var $p=$("<p>"+$text+"</p>");
 $li.append($p);
 //5、把li添加到 <div class="chatBody"><ul></ul></div>中
 $(".chatBody ul").append($li);
      $(".chatText").val('');//清空輸入框 
 }
 }
 });
 </script>
</head>
<body>
<section id="chat">
 <div class="chatBody"><ul></ul></div>
 <div><img src="images/icon.jpg"></div>
 <textarea class="chatText"></textarea>
 <div class="btn"><span>關(guān)閉(C)</span><span id="send">發(fā)送(S)</span></div>
</section>
</body>
</html> 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論