jquery实现聊天机器人
(编辑:jimmy 日期: 2025/9/16 浏览:3 次 )
本文实例为大家分享了jquery实现聊天机器人的具体代码,供大家参考,具体内容如下
<!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> <link rel="stylesheet" href="./demo.css" rel="external nofollow" > </head> <body> <div class="wrapper"> <h4 class="header">俊凯</h4> <div class="content"> <div class="mine"> <img src="/UploadFiles/2021-04-02/5.jpg">CSS:
* { padding: 0; margin: 0; } ::-webkit-scrollbar { width: 0px; } html, body { height: 100%; } .wrapper { width: 600px; margin: 0 auto; border: 1px solid #eee; height: 100%; position: relative; background-color: #eee; /* overflow: hidden; */ } .wrapper .content { /* overflow-x: hidden; overflow-y: scroll; */ overflow: auto; height: calc(100% - 110px); line-height: 30px; padding: 10px; } .wrapper .header { background-color: grey; text-align: center; color: #fff; height: 40px; line-height: 40px; font-weight: 700; } .wrapper .content .mine { float: right; width: 400px; } .wrapper .content .robot { float: left; width: 400px; } .wrapper .content img { width: 30px; height: 30px; border-radius: 50%; vertical-align: middle; } .content .mine img { float: right; } .content .mine .text { float: right; background-color: greenyellow; } .content .robot img { float: left; } .content .robot .text { float: left; background-color: #fff; } .text { max-width: 250px; font-size: 16px; padding: 0 10px; border-radius: 3px; /* border: 1px solid #fff; */ } .inp { width: 100%; height: 50px; line-height: 50px; position: absolute; bottom: 0px; font-size: 0; text-align: center; /* padding: 0 10px; */ background-color: #ddd; /* vertical-align: middle; */ } .inp input { width: calc(100% - 80px); height: 30px; line-height: 30px; border: none; outline: none; font-size: 14px; display: inline-block; vertical-align: middle; } .inp button { width: 60px; height: 30px; font-size: 14px; border: none; outline: none; background-color: #ccc; display: inline-block; vertical-align: middle; cursor: pointer; }js:
$('#submit').click(function(){ var val = $('#word').val(); if(val){ renderDom('mine',val) $('#word').val('') $.ajax({ type:'GET', url:'http://temp.duyiedu.com/api/chat', data:{ text:val }, dataType:'json', success:function(res){ // console.log(res) renderDom('robot',res.text); } }) } }) $('#word').on('keyup',function (e){ if(e.keyCode == 13){ $('#submit').click() } }) function renderDom(role,text){ $(` <div class="${role}"> <img src="/UploadFiles/2021-04-02/${role == 'mine' ">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇:js实现踩五彩块游戏
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?