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

jQuery實現(xiàn)聊天對話框

 更新時間:2020年02月08日 11:19:15   作者:舍平凡愛動蕩  
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)聊天對話框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了jQuery實現(xiàn)聊天對話框的具體代碼,供大家參考,具體內(nèi)容如下

效果圖:左下角選擇對話的角色,在對話框輸入消息點擊發(fā)送按鈕,消息顯示在上面界面當中,然后對話框內(nèi)容被清空。

<!DOCTYPE html>
<html lang="en">
 
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style type="text/css">
    .talk_con {
      width: 600px;
      height: 500px;
      border: 1px solid #666;
      margin: 50px auto 0;
      background: #f9f9f9;
    }
 
    .talk_show {
      width: 580px;
      height: 420px;
      border: 1px solid #666;
      background: #fff;
      margin: 10px auto 0;
      overflow: auto;
    }
 
    .talk_input {
      width: 580px;
      margin: 10px auto 0;
    }
 
    .whotalk {
      width: 80px;
      height: 30px;
      float: left;
      outline: none;
    }
 
    .talk_word {
      width: 420px;
      height: 26px;
      padding: 0px;
      float: left;
      margin-left: 10px;
      outline: none;
      text-indent: 10px;
    }
 
    .talk_sub {
      width: 56px;
      height: 30px;
      float: left;
      margin-left: 10px;
    }
 
    .atalk {
      margin: 10px;
    }
 
    .atalk span {
      display: inline-block;
      background: #0181cc;
      border-radius: 10px;
      color: #fff;
      padding: 5px 10px;
    }
 
    .btalk {
      margin: 10px;
      text-align: right;
    }
 
    .btalk span {
      display: inline-block;
      background: #ef8201;
      border-radius: 10px;
      color: #fff;
      padding: 5px 10px;
    }
  </style>
  <script src='../js/jquery-1.12.4.js'></script>
  <script>
  $(function(){
    $('#talksub').click(function(){
      //發(fā)送單擊,獲取用戶輸入的數(shù)據(jù)value屬性值
      var vals=$('#talkwords').val()
      //如果輸入的數(shù)據(jù)為空,則彈窗提示
      if (vals=='')
      {
        alert('請輸入數(shù)據(jù)!')
        return
      }
      //條件下拉列表中的value值是0還是1
      var whovals=$('#who').val()
      var str=""
      //選擇A發(fā)送還是B發(fā)送
      if (whovals==0){
        str='<div class="atalk"><span>A:'+ vals+'</span></div>'
      }
      else{
        str='<div class="btalk"><span>B:'+ vals+'</span></div>'
      }
      //原有的內(nèi)容+str,否則會覆蓋掉原有內(nèi)容
      $('#words').html($('#words').html()+str)
      //發(fā)送完數(shù)據(jù)后清空輸入框
      $('#talkwords').val('')
    })
  })
  </script>
</head>
 
<body>
  <div class="talk_con">
    <div class="talk_show" id="words">
      <div class="atalk"><span>A:你還好嗎?</span></div>
      <div class="btalk"><span>B:嗯,你呢?</span></div>
    </div>
    <div class="talk_input">
      <select class="whotalk" id="who">
        <option value="0">A:</option>
        <option value="1">B:</option>
      </select>
      <input type="text" class="talk_word" id="talkwords">
      <input type="button" value="發(fā)送" class="talk_sub" id="talksub">
    </div>
  </div>
</body>
 
</html>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論