jQuery實(shí)現(xiàn)簡易QQ聊天框
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)簡易QQ聊天框的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>例子1</title>
<style type="text/css">
*{list-style: none;margin: 0;padding: 0;}
.box1{
width: 500px;
height: 480px;
border: 1px solid #aaa;
margin: 0 auto;
margin-top: 20px;
}
.box{
width: 500px;
height: 250px;
overflow: auto;
}
#bb{
width: 494px;
margin-top: -5px;
border: 1px solid white;
outline: none;
}
img{
width: 500px;
}
.btn{
margin-left:325px;
}
.btn,.btn1{
background: #069dd5;
width: 80px;
padding: 3px 0;
border-radius: 7px;
color: white;
font-size: 14px;
outline: none;
}
.image{
margin: 5px;
width: 50px;
}
.pp{
margin-left: 60px;
margin-top: -50px;
color: #009494;
margin-bottom: 10px;
}
.ppp{
width: 400px;
margin-left: 60px;
background: #eee;
border-radius: 5px;
padding: 5px;
font-size: 14px;
}
.item{
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="box1">
<div class="box">
<ul class="items"></ul>
</div>
<img src="asd.jpg" alt="">
<textarea name="" id="bb" cols="30" rows="10"></textarea>
<button class="btn">關(guān)閉(c)</button>
<button class="btn1">發(fā)送(s)</button>
</div>
</body>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function(){
var ul = $(".items")
var arr=[1,2,3]
var arr1=["松松","六月的雨","毛毛"]
function num(n,m){
//封裝隨機(jī)數(shù)
return Math.round(Math.random()*(m-n)+n)
}
$(".btn1").click(function(){
//創(chuàng)建按鈕點(diǎn)擊事件
var li = $("<li></li>")
//創(chuàng)建一個(gè)li標(biāo)簽
var imgs = $("<img src='' alt=''/>")
//創(chuàng)建一個(gè)img標(biāo)簽
var h4 = $("<h4></h4>")
//創(chuàng)建一個(gè)h4標(biāo)簽
var p = $("<p></p>")
//創(chuàng)建一個(gè)p標(biāo)簽
var val = bb.value;
//獲取文本域的值
p.html(val);
//把文本域的值賦給p標(biāo)簽
$(p).addClass("ppp")
//給p標(biāo)簽加一個(gè)css樣式
$(li).addClass("item")
//給li加一個(gè)css樣式
li.appendTo(ul)
//把li插入到ul內(nèi)
bb.value = "";
//清空文本域內(nèi)容
var arr2 = num(0,arr.length-1)
//提取隨機(jī)數(shù)
$(h4).addClass("pp")
//給h4添加css樣式
h4.html(arr1[arr2])
//給h4賦值
$(imgs).attr({"src":arr[arr2]+".jpg"})
//給img添加屬性和屬性值
$(imgs).addClass("image")
//給img添加一個(gè)css樣式
p.appendTo(li)
//將p標(biāo)簽插入li內(nèi)
h4.prependTo(li)
//將h4標(biāo)簽插入li內(nèi)
imgs.prependTo(li)
//將img標(biāo)簽插入li內(nèi)
$(".box").scrollTop($(".box")[0].scrollHeight);
//讓滾動條始終在最底端
})
})
</script>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于jQuery實(shí)現(xiàn)的水平和垂直居中的div窗口
在建立網(wǎng)頁布局的時(shí)候,我們經(jīng)常會面臨一個(gè)問題,就是讓一個(gè)div實(shí)現(xiàn)水平和垂直居中,雖然好幾種方式實(shí)現(xiàn),但是今天介紹時(shí)我最喜歡的方法,通過css和jQuery實(shí)現(xiàn)。2011-08-08
jQuery實(shí)現(xiàn)彈窗下底部頁面禁止滑動效果
在項(xiàng)目開發(fā)過程中,經(jīng)常會遇到帶有彈窗的頁面,尤其是在移動端。下面通過本文給大家分享jQuery實(shí)現(xiàn)彈窗下底部頁面禁止滑動效果,需要的朋友參考下吧2017-12-12
jQuery 實(shí)現(xiàn)ajax傳入?yún)?shù)含有特殊字符的方法總結(jié)
在做ajax登錄時(shí)候遇到的一個(gè)問題,當(dāng)傳入?yún)?shù)含有特殊字符,比如:“$'#@”等。參數(shù)傳遞會有問題,無法正確獲取。本文章向碼農(nóng)介紹jQuery ajax特殊字符參數(shù)解決方法,需要的朋友可以參考一下。2016-10-10
jquery.cookie.js 操作cookie實(shí)現(xiàn)記住密碼功能的實(shí)現(xiàn)代碼
jquery.cookie.js操作cookie實(shí)現(xiàn)記住密碼功能,很簡單很強(qiáng)大,喜歡的朋友可以參考下。2011-04-04
jQuery正則驗(yàn)證注冊頁面經(jīng)典實(shí)例
這篇文章主要介紹了jQuery正則驗(yàn)證注冊頁面功能,涉及針對用戶名、密碼、郵箱、手機(jī)號等的正則驗(yàn)證操作技巧,需要的朋友可以參考下2017-06-06
Jquery加載時(shí)從后臺讀取數(shù)據(jù)綁定到dropdownList實(shí)例
從后臺讀取數(shù)據(jù)綁定到dropdownList,option選項(xiàng)value動態(tài)賦值,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06
純jquery實(shí)現(xiàn)模仿淘寶購物車結(jié)算
在淘寶購物,需要把商品加入購車,其中包含全選、單選金額改變,當(dāng)增加商品時(shí)金額也會相應(yīng)的發(fā)生變化,下面通過本文給大家分享純jquery實(shí)現(xiàn)模仿淘寶購物車結(jié)算,需要的朋友可以參考下2015-08-08

