Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
现在在焦点上,输入字段只是隐藏了清除搜索按钮。我需要在焦点事件上添加什么以突出显示输入字段中的值,以便当用户单击输入字段时,选择先前搜索中已经存在的文本?
$('input.query').on('focus',function(){ $("#searchx").hide(); }); $('input.query').on('blur',function(){ $("#searchx").show(); });
答案:将此添加到焦点事件中:
$(this).select();
如果您担心跨浏览器功能,这会更好,
$(document).ready(function() { $("input.query") .focus(function () { $("#searchx").hide(); $(this).select(); }).mouseup(function (e) {e.preventDefault(); }); });