如何以编程方式禁用<input type =“text”/>元素的自动选择?

时间:2010-11-14 21:55:12

标签: javascript jquery html

然后用户使用TAB或SHIFT-TAB“跳转”到某个文本框,并且该文本框中恰好有一个值,然后该值将被自动选中。我想禁用此行为。

我认为可以在focusin事件处理程序中完成:

$("input:text").focusin(function() {
    // "un-select" the value and place the text-cursor
    // at the beginning or end of the value
});

1 个答案:

答案 0 :(得分:3)

$(function() {
    $('input').bind('focus', function(e) {
       return false;
    });
});

使用jQuery 1.4.3+,您可以使用快捷方式:

$(function() {
    $('input').bind('focus', false);
});

示例:http://www.jsfiddle.net/P8LDB/