ppp

太难了。

http://www.webfront-js.com/
大神网站

<head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> @import "../css/day0408.css"; </style> </head> <body> <input id="appinput" type="text" value="123456789asdfcvxc678"> <textarea id="app">123456789asdfcvxc6789asdfcvxc 12345 123456789asdfcvxc</textarea>
<script type="text/javascript">
    let app = document.getElementById('app')

    let appinput = document.getElementById('appinput')


    document.flg = true
    let appcount = 0
    let windowcount = 0

    let posStart = 0
    let posEnd = 0

    app.addEventListener('mousedown', function(e) {
        console.log('app.onmousedown come in == ' + appcount++ + ' selectionStart == ' + this.selectionStart)
            //通过是否支持createTextRange判断是否是IE
        if (this.createTextRange) {
            var rg = this.createTextRange();
            rg.collapse(false);
            rg.select();
        } else {
            var th = this;
            //这里注意一定要定义this为一个变量
            //setTimeout才能从变量作用域中得到这个对象
            //否则其延迟是由window调用的,this指向的是globle对象。
            setTimeout(function() {
                var len = th.value.length;
                th.setSelectionRange(len, len);
            }, 20);
        }

    }, true)

    function do1(e) {
        let curpos = e.selectionStart
        let nextpos = e.value.indexOf('\n', curpos)
        let prepos = e.value.substr(0, curpos).lastIndexOf('\n') + 1
        console.log(prepos + ' ' + curpos + ' ' + nextpos)
        if (prepos == curpos) {
            e.setSelectionRange(nextpos, nextpos);
        }
    }
</script>
</body>
posted @ 2021-04-11 01:49  KutsuHaku  阅读(31)  评论(0编辑  收藏  举报
页脚 HTML 代码