gpt4 book ai didi

javascript - 在 chrome 中点击 setSelectionRange 不会在第二次点击时选择

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:51:44 25 4
gpt4 key购买 nike

我有一个函数可以选择输入 onclick 的前 5 个字符。这适用于第一次点击。当输入框仍然有焦点时,在 chrome 中,前 5 个字符内的第二次单击会删除选择,插入符号会在单击的位置闪烁。

我希望前 5 个字符仍处于选中状态。

这似乎是一个 chrome 问题,因为它在 Firefox 中运行良好。

这是我的 fiddle : http://jsfiddle.net/valamas/3eaYq/2/

我怎样才能让它与 chrome 一起工作?

我尝试使用

重置选择
sender.setSelectionRange(0, 1);
sender.setSelectionRange(0, 5);

最佳答案

这确实是 an issue with Chromium (那是一个两年前的问题)。要使 Chrome 的行为与 Firefox 相同,只需将 doSelect 的内容包装在 setTimeout 调用中:

function doSelect(sender, e) {
setTimeout(function(){
sender.setSelectionRange(0, 5);
}, 0);
}

另请参阅:the updated JS Fiddle


更新:该错误现已标记为已修复,并将在 Chrome 39 中提供。

关于javascript - 在 chrome 中点击 setSelectionRange 不会在第二次点击时选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com