CSS 如何从css设置文本框的只读属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2528462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set readonly property of textbox from css
提问by PHP Ferrari
i create css code like
我创建了 css 代码,例如
.inputHide {
font-size : 100px;
width : 100px;
height : 100px;
border : none;
background : transparent;
readonly : true;
}
But it does not work. Although if i use font-size of 1px then by using tab i can access that textbox & can change it's value.
但它不起作用。虽然如果我使用 1px 的字体大小,那么通过使用选项卡,我可以访问该文本框并可以更改它的值。
Is there any way to make textbox readonly just using css..
有什么方法可以只使用css使文本框只读..
采纳答案by David
I agree with rowland but you can set it uneditable with:
我同意 rowland,但您可以将其设置为不可编辑:
.inputHide {
display: none;
}
although this takes it out of the flow (so there is a noticable movement of elements to fill the void your textbox left).
尽管这会将其从流程中移除(因此元素的显着移动以填充文本框左侧的空白)。
This method makes it completely invisible and uneditable... not just visible and greyed out (like HTML "disabled" or "readonly" attributes would do).
这种方法使它完全不可见和不可编辑......不仅仅是可见和变灰(就像 HTML“禁用”或“只读”属性一样)。
回答by J D
For people coming to this answer now. You can do this now with
对于现在来到这个答案的人。你现在可以用
pointer-events: none;
回答by Rowland Shaw
You don't set the behaviour of controls via CSS, only their styling - if you need to make it read-only, flag it as such on the actual control
您不通过 CSS 设置控件的行为,只设置它们的样式 - 如果您需要将其设置为只读,请在实际控件上将其标记为这样
回答by Ionu? Staicu
Readonly is not a STYLE attribute. So you can't set with CSS (cascading STYLE sheet).
Readonly 不是 STYLE 属性。所以你不能用 CSS(层叠样式表)设置。
回答by Jacob K
css cannot be used for making an input readonly. You can use jquery or simple javascript to change the prperty of the fields.
css 不能用于使输入成为只读。您可以使用 jquery 或简单的 javascript 来更改字段的属性。
回答by Johnaxe
$("select").selectize({
onInitialize: function() {
this.$control_input.attr("readonly","readonly");
}
});