我想创建一个CSS类,使输入字段是只读的.
这是我的尝试:
<style>
.enableInput input[readonly] {
color: #CB000F;
}
</style>
<script>
function changeCss()
{
$("#desg").addClass("enableInput input");
}
</script>
</head>
FirstName:<input type="text" name='fname' id='fname' onBlur="changeCss();">
Designation:<input type="text" name='desg' id='desg' value='Software Engr'>
</html>
Run Code Online (Sandbox Code Playgroud)
你不需要用CSS做任何事情.html输入中已存在readonly属性:
<input type="text" name="country" value="Norway" readonly>
Run Code Online (Sandbox Code Playgroud)
没有这样的CSS属性只能简单地输入,但在这个问题中,@ James Donnelly给出了一个解决方法来实现:
.enableInput{
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
317 次 |
最近记录: |