什么是香草JS或jQuery解决方案,将选择一个文本框的所有内容时,文本框接收焦点?


当前回答

onclick="this.focus();this.select()"

其他回答

$(document).ready(function() {
    $("input:text")
        .focus(function () { $(this).select(); } )
        .mouseup(function (e) {e.preventDefault(); });
});
$(document).ready(function() {
    $("input:text").focus(function() { $(this).select(); } );
});

如果你把这些事件链接在一起,我相信就不需要使用.one了,就像本文其他地方建议的那样。

例子:

$('input.your_element').focus( function () {
    $(this).select().mouseup( function (e) {
        e.preventDefault();
    });
});
onclick="this.focus();this.select()"
$(document).ready(function() {
  $("input[type=text]").focus().select();
});