最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery添加div實(shí)現(xiàn)消息聊天框

 更新時(shí)間:2020年02月08日 13:11:00   作者:代碼搬運(yùn)工233  
這篇文章主要為大家詳細(xì)介紹了jquery添加div實(shí)現(xiàn)消息聊天框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了jquery添加div實(shí)現(xiàn)消息聊天框的具體代碼,供大家參考,具體內(nèi)容如下

上代碼

<html>
<head>
<style>
* {
  margin: 0;
  padding: 0;
}

.border {
  margin-left: 300px;
  width: 900px;
  background-color: white;
  position: relative;
  border: 1px solid rgb(221, 221, 221);
}

.border .border-next {
  background-color: #dcad50;
  position: relative;
  height: 23px;
  line-height: 40px;
  display: flex;
  padding: 10px 60px 10px 80px;
}

.border-next .people {
  background-color: #dcad50;
  font-size: 20px;
  color: black;
  font-family: 楷體;
  margin-left: 300px;
}

.border .border-second {
  background-color: white;
  margin-left: 0px;
  width: 700px;
  height: 530px;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid rgb(221, 221, 221);
  border-bottom: 1px solid rgb(221, 221, 221);
}

.border .border-img {
  background-color: white;
  margin-left: 0px;
  width: 700px;
  height: 30px;
  border-right: 1px solid rgb(221, 221, 221);
  border-bottom: 1px solid rgb(221, 221, 221);
}

.border-bottom {
  display: flex;
  width: 700px;
  height: 120px;
  background-color: white;
  overflow: auto;
  font-size: 20px;
  border-style: solid;
  border-color: #FFFFFF;
  border-right: 1px solid rgb(221, 221, 221);
}

.button {
  display: flex;
  margin-left: 530px;
}

.button .shut {
  background-color: white;
  width: 70px;
  height: 30px;
  font-size: 20px;
  text-align: center;
  border: 1px solid rgb(221, 221, 221);
}

.button .send {
  background-color: white;
  margin-left: 15px;
  width: 70px;
  height: 30px;
  font-size: 20px;
  text-align: center;
  border: 1px solid rgb(221, 221, 221);
  background-color: #DBAC50;
}

.replyChat {
  display:flex;
  width: 150px;
  background: #12B7F5;
  border-radius: 5px;
  /* 圓角 */
  position: relative;
  margin-left: 500px;
  align-content: center;
  margin-bottom: 30px;
}

.sendChat {
  display:flex;
  width: 150px;
  background: #E5E5E5;
  border-radius: 5px;
  /* 圓角 */
  position: relative;
  margin-left: 50px;
  align-content: center;
  margin-bottom: 30px;
  border-color: white white white #E5E5E5;
}

.sendChat span {
  display: inline-block;
  margin-left: 10px;
  line-height: 35px;
}

.replyChat span {
  display: inline-block;
  margin-left: 10px;
  line-height: 35px;
}

.sendChat .arrows {
  position: absolute;
  top: 5px;
  left: -16px;
  /* 圓角的位置需要細(xì)心調(diào)試哦 */
  width: 0;
  height: 0;
  font-size: 0;
  border: solid 8px;
  border-color: white #E5E5E5 white white;
}

.replyChat .arrow {
  position: absolute;
  top: 5px;
  right: -16px;
  /* 圓角的位置需要細(xì)心調(diào)試哦 */
  width: 0;
  height: 0;
  font-size: 0;
  border: solid 8px;
  border-color: white white white #12B7F5;
}

.chatTouXiang {
  width: 50px;
  height: 50px;
  border-radius: 50%; 
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  background-image: url(img/tou.png);
}
.chatCnt{

}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>聊天助手</title>
<script src="js/jquery-1.8.3.min.js"></script>
<script>
  window.οnlοad=function(){
    $(".arrow").hide();
    $(".arrows").hide();
  }
  document.onkeydown = function(e) {
    if (e.keyCode == 13 && e.ctrlKey) {
      // 這里實(shí)現(xiàn)換行
      document.getElementById("sendContent").value += "\n";
    } else if (e.keyCode == 13) {
      // 避免回車(chē)鍵換行
      e.preventDefault();
      // 下面寫(xiě)你的發(fā)送消息的代碼
      f();
    }
  }
  function f() {
    var cnt = $("#sendContent").val();
    if(cnt == '')alert('內(nèi)容不能為空');  
    if(cnt != ''){
      var node = document.createElement('div');
      node.className = 'sendChat';
      var span = document.createElement('span');
      span.innerHTML = cnt;
      var arrow = document.createElement('div');
      arrow.className = 'arrows';
      node.appendChild(span);
      node.appendChild(arrow);
      $(".border-second").append($(node));
      $("#sendContent").val('');
      $.ajax({
        data : cnt,
        type : "post",
        url : "CharServlet?id=" + cnt,
        dataType : "json",
        success : function(msg) {
          var node = document.createElement('div');
          node.className = 'replyChat';
          var span = document.createElement('span');
          span.innerHTML = msg.text;
          var arrow = document.createElement('div');
          arrow.className = 'arrow';
          node.appendChild(arrow);
          node.appendChild(span);

          $(".border-second").append($(node));

          var boderSecondDiv = $('.border-second');
          var lastChild = boderSecondDiv[0].lastChild;
          var lastChildH = lastChild.offsetTop;
          var h = 0;
          for (var i = 0, len = lastChild.children.length; i < len; i++) {

            h += lastChild.children[i].offsetHeight;
          }
          boderSecondDiv[0].scrollTop = lastChildH + h;

        },
        error : function(msg) {
          alert("請(qǐng)求失敗");
        }
      });
    }
  }
</script>
</head>

<div class="frame">
  <div class="border">
    <div class="border-next">
      <div class="people">聊天助手</div>
    </div>
    <div class="border-second">
      <div class="chatCnt">
      <div class="chatTouXiang"></div> 
      <div class="sendChat">
        <span></span>
        <div class="arrows"></div>
      </div>
      </div>
      <div class="replyChat">
        <span></span>
        <div class="arrow"></div>
      </div>
      <br>
    </div>
    <div class="border-img"></div>
    <textarea id="sendContent" class="border-bottom"></textarea>
    <div class="button">
      <button class="shut">關(guān)閉</button>
      <button id="selectBtn" class="send" onclick="f()">發(fā)送</button>
    </div>

  </div>
</div>
</body>
</html>

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

相關(guān)文章

  • jQuery插件的寫(xiě)法分享

    jQuery插件的寫(xiě)法分享

    這幾天在學(xué)習(xí)jQuery插件的寫(xiě)法,搜索了一些資料,包括jQuery官方的示例,但發(fā)現(xiàn)描述的并不是很清晰。最后,終于搜索到一篇講解比較清晰的文章,這里自己總結(jié)了一下,并以一個(gè)具體的示例來(lái)說(shuō)明jQuery插件的寫(xiě)法
    2013-06-06
  • jQuery自定義事件的簡(jiǎn)單實(shí)現(xiàn)代碼

    jQuery自定義事件的簡(jiǎn)單實(shí)現(xiàn)代碼

    本篇文章只要是對(duì)jQuery自定義事件的簡(jiǎn)單實(shí)現(xiàn)代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
    2014-01-01
  • 超贊的jQuery圖片滑塊動(dòng)畫(huà)特效代碼匯總

    超贊的jQuery圖片滑塊動(dòng)畫(huà)特效代碼匯總

    本文將為大家收集10個(gè)超贊的jQuery圖片滑塊動(dòng)畫(huà),都是小編精挑細(xì)選而來(lái),希望這些現(xiàn)成的jQuery插件將為你節(jié)省很多開(kāi)發(fā)時(shí)間。
    2016-01-01
  • 如何解決Jquery庫(kù)及其他庫(kù)之間的$命名沖突

    如何解決Jquery庫(kù)及其他庫(kù)之間的$命名沖突

    這篇文章介紹了Jquery庫(kù)及其他庫(kù)之間的$命名沖突的解決方法,有需要的朋友可以參考一下
    2013-09-09
  • jQuery表格插件ParamQuery簡(jiǎn)單使用方法示例

    jQuery表格插件ParamQuery簡(jiǎn)單使用方法示例

    這篇文章主要介紹了jQuery表格插件ParamQuery簡(jiǎn)單使用方法示例,大家參考使用吧
    2013-12-12
  • jQuery插件Slider Revolution實(shí)現(xiàn)響應(yīng)動(dòng)畫(huà)滑動(dòng)圖片切換效果

    jQuery插件Slider Revolution實(shí)現(xiàn)響應(yīng)動(dòng)畫(huà)滑動(dòng)圖片切換效果

    Slider Revolution插件是一款非常強(qiáng)大的插件了,我們可以利用它來(lái)制作出各種效果并且還支持移動(dòng)設(shè)備,支持手機(jī)觸摸,鍵盤(pán)翻頁(yè);它內(nèi)置幻燈、視頻播放計(jì)時(shí)器等等效果,具體我們來(lái)看看。
    2015-06-06
  • jquery 使用簡(jiǎn)明教程

    jquery 使用簡(jiǎn)明教程

    jQuery是目前使用最廣泛的javascript函數(shù)庫(kù)。據(jù)統(tǒng)計(jì),全世界排名前100萬(wàn)的網(wǎng)站,有46%使用jQuery,遠(yuǎn)遠(yuǎn)超過(guò)其他庫(kù)。微軟公司甚至把jQuery作為他們的官方庫(kù)。對(duì)于網(wǎng)頁(yè)開(kāi)發(fā)者來(lái)說(shuō),學(xué)會(huì)jQuery是必要的。因?yàn)樗屇懔私鈽I(yè)界最通用的技術(shù),為將來(lái)學(xué)習(xí)更高級(jí)的庫(kù)打下基礎(chǔ),并且確實(shí)可以很輕松地做出許多復(fù)雜的效果
    2014-03-03
  • jQuery插件實(shí)現(xiàn)靜態(tài)HTML驗(yàn)證碼校驗(yàn)

    jQuery插件實(shí)現(xiàn)靜態(tài)HTML驗(yàn)證碼校驗(yàn)

    這篇文章主要介紹了jQuery插件實(shí)現(xiàn)靜態(tài)HTML驗(yàn)證碼校驗(yàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-11-11
  • jquery屬性過(guò)濾選擇器使用示例

    jquery屬性過(guò)濾選擇器使用示例

    下面以一個(gè)示例:所有具有id屬性的元素設(shè)置樣式,動(dòng)畫(huà)效果,為大家介紹下jquery屬性過(guò)濾選擇器的使用方法,感興趣的朋友可以參考下哈
    2013-06-06
  • jQuery Validation插件remote驗(yàn)證方式的Bug解決

    jQuery Validation插件remote驗(yàn)證方式的Bug解決

    jQuery插件很多,其中一個(gè)重要的插件便是jQuery Validation,它的作用是對(duì)表單進(jìn)行驗(yàn)證,還上了jQuery官網(wǎng)。
    2010-07-07

最新評(píng)論

五莲县| 和静县| 柳河县| 调兵山市| 新建县| 理塘县| 托克逊县| 虞城县| 辽阳市| 建始县| 东丰县| 宁海县| 锡林郭勒盟| 巨鹿县| 镶黄旗| 虹口区| 高要市| 兰州市| 柯坪县| 巴彦淖尔市| 丰县| 晋中市| 太保市| 上饶县| 大丰市| 云和县| 新营市| 永福县| 宾阳县| 新乡县| 方城县| 嘉峪关市| 临武县| 大邑县| 东乌珠穆沁旗| 武平县| 陆丰市| 内丘县| 泰来县| 改则县| 乌拉特前旗|