且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery在焦点上选择文本不工作在Safari和Chrome

更新时间:2023-11-05 19:47:40

这是导致选择获取的onmouseup事件所以你只需要添加:

$ $ p $ $ $ $$ souper_fancymouseup(function(e){
e.preventDefault();
});


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() });

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();
});