- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个函数可以选择输入 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);
}
更新:该错误现已标记为已修复
,并将在 Chrome 39 中提供。
关于javascript - 在 chrome 中点击 setSelectionRange 不会在第二次点击时选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047648/
menu Home Events Technical Schedule
我试图阻止触发默认 anchor 链接和 onclick 事件。 这是 HTML 代码: Google 我正在尝试使用以下 jQuery 代码阻止任何重定向的发生: $("#mylink").cli
我想在单击父 div 上的任意位置时切换我的 div,除非单击 anchor 元素。因此,例如,如果我单击示例中的第一个文本,我希望它切换,但在我的示例中的第二个文本上,我不希望它切换。 JSFidd
我在通过 jQuery 伪造 anchor 点击时遇到问题:为什么我的thickbox在我第一次点击输入按钮时出现,但第二次或第三次却没有出现? 这是我的代码: Link 当我直接点击链接时,它总是
我已经从 Mootools 切换到 jQuery,因为我认为它有更好的支持。我有这样的 HTML: Opcje Opcje Opcje Opcje Opcje Opcje Opcje JS
我是一名优秀的程序员,十分优秀!