首页 > 解决方案 > Internet Explorer 11,如何设置只读样式?

问题描述

我正在仔细检查我的网站是否与其他浏览器一起一切正常。

我注意到在 Chrome 中我可以设置只读样式,但在 Internet Explorer 中你不能设置它的样式。

我通常禁用输入字段,但这个只读字段需要只读才能将其放入数据库。

如果不可能。我希望只读输入不集中在鼠标单击上。因为我现在有一个带有占位符的只读输入字段。如果我在只读输入中单击,则文本消失。因此,如果我在其中单击,输入可以更改。如果我的第一个问题无法完成,可以防止这种情况吗?

谢谢你的时间,我很感激。

HTML 只读(需要它是只读的,因为我必须发布它)

<input id='overNightRate' type='text' name='overNightRate' class='form-control disabledDesign' placeholder="Bedrag word berekent" readonly/>

CSS

.disabledDesign:read-only{background-color:#003c85;
  color: white;
opacity: 1;}

而且我有更多相同的输入字段,但只是计算某些东西的总和。这也需要是只读的,因为它需要将输入数据存储到数据库中

标签: htmlcssinternet-explorer-11readonly

解决方案


如果需要的话readonly,我相信 IE 11 支持 attr 选择器:

.disabledDesign[readonly='readonly'] {
  background-color: #003c85;
  color: white;
  opacity: 1;
  pointer-events: none;
}
<input id='overNightRate' type='text' name='overNightRate' class='form-control disabledDesign' placeholder="Bedrag word berekent" readonly="readonly" />

编辑:在 IE11 上测试并按预期工作。


推荐阅读