http://www.webfront-js.com/
大神网站
<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('
', curpos)
let prepos = e.value.substr(0, curpos).lastIndexOf('
') + 1
console.log(prepos + ' ' + curpos + ' ' + nextpos)
if (prepos == curpos) {
e.setSelectionRange(nextpos, nextpos);
}
}
</script>