How to disable a textbox in CSS? Currently we are having a textbox in our view which can be enabled/disabled depending on a property in the model. We are having asp.net MVC view; depending on the value of the Model property we need to either render a textbox or readonly textbox. we were thinking of doing this by applying CSS to the view control. Has someone done this earlier?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
you can disable via css:
Doesn't work everywhere though.
**just copy paste this code and run you can see the textbox disabled **
Short answer
No, you can't disable a textbox using CSS.
Long answer
pointer-events: none
works but on IE the CSS property only works with IE 11 or higher, so it doesn't work everywhere on every browser. Except for that you cannot disable a textbox using CSS.However you could disable a textbox in HTML like this:
But if the textbox is in a form and you want the value of the textbox to be not submitted, instead do this:
So the difference between these two options for disabling a textbox is that
disabled
cannot allow you to submit the value of theinput
textbox butreadonly
does allow.For more information on the difference between these two, see "What is the difference between
disabled="disabled"
andreadonly="readonly"
.another way is by making it readonly
You can't disable a textbox in CSS. Disabling it is not a presentational task, you will have to do this in the HTML markup using the
disabled
attribute.You may be able to put something together by putting the textbox underneath an absolutely positioned transparent element with z-index... But that's just silly, plus you would need a second HTML element anyway.
You can, however, style disabled text boxes (if that's what you mean) in CSS using
from IE7 upwards and in all other major browsers.
Going further on Pekka's answer, I had a style "style1" on some of my textboxes. You can create a "style1[disabled]" so you style only the disabled textboxes using "style1" style:
Worked ok on IE8.