为了账号安全,请及时绑定邮箱和手机立即绑定

input.select()后如何突出显示输入中的双击单词

input.select()后如何突出显示输入中的双击单词

冉冉说 2021-05-16 10:02:45
有一些文本输入。输入聚焦时(第一次单击输入),必须选择此输入中的所有文本;第二次单击输入时,必须选择特定的单词。我尝试实现与Chrome(版本74.0.3729.131(正式版本)(64位))中的URL栏相同的功能。您可以在此处查看输入的当前行为:https : //jsfiddle.net/deaamod1s/rh5mw0e4/23/我看到的唯一解决方案是检查是否双击输入,然后如果未双击输入,则执行此操作 input.select()input.onfocus = function(e) {        let hasValueWhenGotFocused = false;        if (input.value) {            hasValueWhenGotFocused = true;        }        setTimeout(() => {            if (hasValueWhenGotFocused && this.className.indexOf("doubleclicked") == -1) {                    this.select();            } else {                this.classList.remove("doubleclicked");            }        },400);  }    input.ondblclick = function(e){        this.classList.add('doubleclicked');    }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 143 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信