即时通讯原生js实现表情输入(就是简单输入 并没有实现即时通讯 功能)

 

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    div{
        width: 500px;
        moz-user-select:none; /* Firefox私有属性 */
        -webkit-user-select:none; /* WebKit内核私有属性 */
        -ms-user-select:none; /* IE私有属性(IE10及以后) */
        -khtml-user-select:none; /* KHTML内核私有属性 */
        -o-user-select:none; /* Opera私有属性 */
        user-select:none; /* CSS3属性 */
    }
    p{
        width: 500px;
        height: 200px;
        border: 1px solid #eee;
        overflow: hidden;
        overflow-y: auto;
        padding: 10px;
        -webkit-user-modify: read-write;
    }
    p:focus {
        outline:none;
        border: 1px solid pink;
    }
    button {
        border:none;
        background:purple;
        color: #FFf;
        border-radius: 5px;
        outline:none;
        width: 80px;
        height: 40px;
        position: absolute;
        top:400px;
        left: 400px;
    }
</style>
<body>
    <div></div>
    <p contenteditable="true" oninput="num(this)"></p>
    <button>发送</button>
</body>
<script>
    var html=""
    for (var i=0;i<135;i++) {
        html+=`<img src="./${i<10?0:""}${i}.gif" data-path="./${i<10?0:""}${i}.gif" onclick="add(this)"/>`
    }

    document.querySelector("div").innerHTML=html

    function add(a) {
        var path = a.dataset.path
        var str=`<img src="${path}" />`
        document.querySelector("p").innerHTML+=str
    }

    function num(str) {
        console.dir(str.innerHTML.length)
    }
</script>
</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值