简体   繁体   中英

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/

You still need to click outside the input to trigger the blur ofcourse

EDIT2

WHat would you like to achieve. 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">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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