如何以编程方式禁用自动选择< input type = text>元素? [英] How to programmatically disable auto-select on <input type=text> elements?

查看:82
本文介绍了如何以编程方式禁用自动选择< input type = text>元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Then the user uses TAB or SHIFT-TAB to "jump" to a certain text-box and that text-box happens to have a value in it, then that value will be auto-selected. I would like to disable this behavior.

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

I assume that can be done inside the focusin event handler:

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


推荐答案

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

使用jQuery 1.4.3+可以使用快捷版:

Using jQuery 1.4.3+ you can use the shortcut version:

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

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

这篇关于如何以编程方式禁用自动选择< input type = text>元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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