智能在线客服系统布局二:javascript

Original 2019-03-08 16:25:50 225
abstract:<!DOCTYPE html> <html>          <head>         <meta charset="UTF-8">  
<!DOCTYPE html>
<html>
    
    <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>智能在线客服系统布局二:javascript</title>
        <style>
        * {
            margin: 0;
            padding: 0;
        }
        .main {
            margin: 20px auto;
            width: 450px;
            height: 680px;
            background: #87CEFA;
            box-shadow: 2px 2px 10px #888;
            border-radius: 10px;
        }
        h2 {
            text-align: center;
            padding: 10px 0;
            color: #fff;
            border-bottom: 2px solid #fff;
        }
        .content {
            width: 400px;
            height: 500px;
            background: #EFEFEF;
            margin: 20px auto 10px;
            border: 6px double lightgreen;
        }
        ul {
            list-style: none;
            line-height: 2em;
            overflow: hidden;
            padding: 15px;
        }
        .sub {
            float: left;
            width: 480px;
            margin: 10px auto;
            position: relative;
        }
        textarea {
            width: 350px;
            height: 50px;
            resize: none;
            outline: none;
            position: absolute;
            left: 20px;
            border: 0;
            font-size: 16px;
            color: red;
        }
        button {
            width: 58px;
            height:50px;
            background: red;
            color: #fff;
            position: absolute;
            left: 370px;
            border: 0;
        }
        button:hover {
            background: black;
            cursor: pointer;
        }
        </style>
    </head>
    
    <body>
        <div>
             <h2>在线客服</h2>

            <div>
                <ul>
                    <li></li>
                </ul>
            </div>
            <div>
                <textarea name="text"></textarea>
                <button type="button">发送</button>
            </div>
        </div>
        <script>
            var text = document.getElementsByTagName('textarea')[0];
            var ul = document.getElementsByTagName('ul')[0];
            var btn = document.getElementsByTagName('button')[0];
            var sum = 0;
            text.focus();
            btn.onclick = function() {
                if (text.value.length === 0) {
                    alert('您好,请输入内容');
                    return false;
                }
                var userContent = text.value;
                text.value = '';
                var li = document.createElement('li');
                li.innerHTML = userContent;
                var userPic = '<img src="dom/inc/peter.jpg" width="30" style="border-radius:50%">';
                li.innerHTML = userPic + ' ' + userContent;
                ul.appendChild(li);
                sum += 1;
                setTimeout(function() {
                    var info = [
                        '您好,有什么需要能帮助您的?',
                        '今天的天气挺不错!',
                        '周末大酬宾,让利50%,欢迎选购!',
                        '退货还是换货了?',
                        '活动还有2天的时间,抓紧行动了。'
                    ];
                    var temp = info[Math.floor(Math.random() * 5)];
                    var reli = document.createElement('li');
                    var kefuPic = '<img src="dom/inc/zly.jpg" width="30" style="border-radius:50%;">';
                    reli.innerHTML = kefuPic + ' ' + '<span style="color:red">' + temp + '</span>';
                    ul.appendChild(reli);
                    sum += 1;
                }, 2000);

                if (sum > 10) {
                    ul.innerHTML = '';
                    sum = 0;
                }

            }
        </script>
    </body>

</html>


Correcting teacher:韦小宝Correction time:2019-03-09 09:12:30
Teacher's summary:写的还算是很不错的 没事要记得多去练习练习哦 可以考虑使用jQuery来把这个项目改写一下

Release Notes

Popular Entries