返回模拟智能在线客......登陆

模拟智能在线客服系统

至诚网络2019-06-07 16:51:19281

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>DOM实战 模拟智能在线客服系统</title>

    <style>

        div:nth-child(1){

            width: 450px;

            height: 650px;

            background-color: lightskyblue;

            margin: 30px auto;

            color: #333;

            box-shadow: 2px 2px 2px #808080;

        }

        h2{text-align:center;margin-bottom: 10px;}

        div:nth-child(2){width: 400px;height: 500px;border:4px double green;background-color: #efefef;margin: 20px auto 10px;}

        ul{list-style-type: none;line-height: 2em;overflow: hidden;padding: 15px;}

        table{width: 90%;height: 80px;margin: auto;}

        textarea{border: none;resize: none;background-color: lightyellow;}

        button{width: 60px;height: 40px;background-color: seagreen;color: white;border: none;}

        button:hover{cursor: pointer;background-color: orange;}

    </style>

</head>

<body>

<div>

    <h2>在线客服</h2>

    <div>

        <ul>

            <li>

 

            </li>

        </ul>

    </div>

    <table>

        <tr>

            <td align="right"><textarea name="text" id="" cols="50" rows="3"></textarea></td>

            <td align="left"><button type="button">发送</button></td>

        </tr>

    </table>

</div>

 

<script>

    //获取到页面中的相关元素

    let btn =document.getElementsByTagName('button')[0];

    let text = document.getElementsByName('text')[0];

    let list = document.getElementsByTagName('ul')[0];

    let sum = 0; // 计数器

 

    // 添加点击事件 获取用户说的内容并发送到窗口

    btn.onclick = function () {

        // 获取用户提交的内容

        if(text.value.length === 0){

            alert('是不是忘记说点什么');

            return false;   //有个知识点 : 表单提交的时候 如果函数返回 false  表单就不提交了 ,切记!

            // 1. return ;  return false  return true 都会在函数内部阻止程序的执行。

 

            // 2. 只有 return false 会阻止表单的提交。

        }

        let userComment = text.value; //将用户提交的内容获取并保存

        text.value = ''; // 立即将用户留言区清空

 

        // 创建一个li

        let li = document.createElement('li');

 

        // 用户头像

        let userPic = '<img src="1.jpg" width="35px;" style="border-radius: 50%;">';

        li.innerHTML = userPic +' '+ userComment;

        list.appendChild(li); // 将用户信息添加到聊天窗口中

        sum +=1;

 

        //设置定时器 2秒后自动回复

        setTimeout(function () {

            //自动回复信息的模板

            let info = [

                '好的亲,什么事尽管问',

                '要退款吗?稍等我确认下',

                '现在好忙,空时回复你',

                '还要等等啦,在审请了',

                '说不清楚,直接打我电话133xxxxxxxx'

            ];

            let temp = info[Math.floor(Math.random()*4)];

            let reply = document.createElement('li');

            let kefupic = '<img src="3.png" width="35px;" style="border-radius: 50%;">';

            reply.innerHTML = kefupic + ' ' + '<span style="color:red;">' + temp + '</span>';

            list.appendChild(reply);

            sum += 1;

 

        },2000);

 

        // 清空窗口 并将计数器清零

        if (sum > 10){

             list.innerHTML = '';

             sum = 0;

        }

    }

</script>

</body>

</html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送