完全只读转换HTML文本框

Roh*_*rma 0 html javascript css jquery

要求:使文本字段只读 - 未禁用,用户甚至不能单击该字段一次(或多或少的文本字段应该像选择框一样).用户按下tab时应该能够移动到下一个字段(正常行为)Internet Explorer应该是用于呈现代码的浏览器.

我一直在做的示例代码就在这里

<table>
<tr>
<td><input type="text" value="test1" onfocus="this.blur()" readonly="true" /></td>
</tr>
<tr>
<td><input type="text" value="test2" onfocus="this.blur()" readonly="true" /></td>
</tr>
<tr>
<td><input type="text" value="test3" onfocus="this.blur()" readonly="true" /></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)

上述代码的问题是1.用户可以单击一次(闪烁光标可见)2.按Tab键 - 用户不会移动到下一个字段.

仅适用于IE.谢谢

kar*_*ark 5

要解决标签问题,您可能需要添加tabindex到输入:

<input type="text" value="test1" onfocus="this.blur()" readonly="readonly" tabindex="1"/>
<input type="text" value="test2" onfocus="this.blur()" readonly="readonly" tabindex="2"/>
<input type="text" value="test3" onfocus="this.blur()" readonly="readonly" tabindex="3"/>
Run Code Online (Sandbox Code Playgroud)