简体   繁体   English

禁用动态启用文本字段

[英]disable enable a textfield dynamically

Hi I was trying to make a textfield dynamic. 嗨,我正在尝试使文本字段动态化。 This is my code 这是我的代码

 <input type="text" id="test1" value ="dynamic" onfocus="this.disabled=true" onblur="this.disabled=false">
    <input type="text" id="test2">

so fields get disabled perfectly but doesnt get enabled on blur. 因此,字段会被完全禁用,但不会在模糊时启用。 If any one here can solve my problem that would be great. 如果任何人都可以解决我的问题,那将是很大的。

Perhaps in this situation it is better to make the field readonly and add some custom class to make it look like it is disabled. 也许在这种情况下,最好使该字段为只读,并添加一些自定义类以使其看起来像被禁用。

\n

Since disabled element are well... disabled :) 由于禁用元素很好...禁用:)

EDIT 编辑

I've done some testing and it gets enabled again on blur! 我已经做过一些测试,并且在模糊状态下再次启用了它!

http://jsfiddle.net/dfhHz/ http://jsfiddle.net/dfhHz/

You still need to click outside the input to trigger the blur ofcourse 您仍然需要在输入之外单击以触发课程模糊

EDIT2 编辑2

WHat would you like to achieve. WHat您想实现。 Since this functionality looks a bit strange (disable on focus and enable on blur) to me :) 由于此功能对我来说有点奇怪(禁用对焦并启用模糊):)

为什么不在文本字段中使用onmouseover和onmouseout事件呢?

<input type="text" id="test1" value="dynamic" onmouseover="this.disabled=true" onmouseout="this.disabled=false">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM