使用 jQuery 选择焦点文本在 Safari 和 Chrome 中不起作用 [英] Selecting text on focus using jQuery not working in Safari and Chrome

查看:21
本文介绍了使用 jQuery 选择焦点文本在 Safari 和 Chrome 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 jQuery 代码(类似于这个问题),在 Firefox 和 IE 中工作,但失败(没有错误,只是不起作用)在 Chrome 和 Safari 中.有什么解决方法的想法吗?

I have the following jQuery code (similar to this question) that works in Firefox and IE, but fails (no errors, just doesn't work) in Chrome and Safari. Any ideas for a workaround?

$("#souper_fancy").focus(function() { $(this).select() });

推荐答案

是 onmouseup 事件导致选择被取消选择,所以你只需要添加:

It's the onmouseup event that is causing the selection to get unselected, so you just need to add:

$("#souper_fancy").mouseup(function(e){
    e.preventDefault();
});

这篇关于使用 jQuery 选择焦点文本在 Safari 和 Chrome 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆