文本框重点突出

San*_*osh 4 javascript jquery textbox focus

当我关注时,我需要从文本框中集中注意力.

我尝试设置外部div的焦点,并在IE中工作正常但不在mozilla中.

我该怎么做呢?

这是我目前的代码:

<div id="outer"> <input type = "textbox" /></div> Onfocus: document.getElementById("outer").focus()
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 6

我想知道如果用户永远不会在里面写任何内容,在这种情况下使用文本框的目的是什么.只需添加一个disabled="disabled"属性或readonly="readonly"(如果您想发布该值).


And*_*y E 5

在 HTML 中:

<input type="text" onfocus="this.blur();" />
Run Code Online (Sandbox Code Playgroud)

在JS中:

document.getElementById("input1").onfocus = function () { this.blur(); }
Run Code Online (Sandbox Code Playgroud)

某些元素在不可编辑的情况下无法接受焦点。


San*_*osh 3

我已经尝试了所有答案,但并非在所有浏览器中都有效。我将所有内容组合在一起。

  1. TextBox.readonly = true;

焦点:

  1. var curText = TextBox.value; TextBox.value = ""; TextBox.value = curText;

  2. TextBox.blur();

  3. TextBox_Parent.focus()

并且它在所有浏览器中都工作正常