【发布时间】:2015-01-03 05:37:25
【问题描述】:
我一直在尝试制作自己的按钮,但由于某种原因,我似乎无法让 :disable 正常工作。我希望禁用该按钮(不响应单击和灰色文本)。我错过了什么?
HTML:
<!doctype html>
<div id="menu">
<a class="button" disabled="true" id="button">Click</a>
</div>
CSS:
.button {
display: block;
width: 40%;
text-align: center;
float: left;
color: #000000;
font-size: 10px;
padding: 0.5em 1em;
text-decoration: none;
-webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
/* Rules below not implemented in browsers yet */
-o-user-select: none;
user-select: none;
}
.button:hover {
background: #f0f0f0;
text-decoration: none;
}
.button:active {
background: rgb(150, 150, 150);
background-image: linear-gradient(to bottom, rgb(150, 150, 150), rgb(200, 200, 200));
text-decoration: none;
}
.button:disabled {
color:rgb(150, 150, 150);
}
此外,这将与 javascript 一起使用。这在js中是否足以改变禁用状态?
button = document.querySelector("#button");
button.disabled = true;
【问题讨论】:
标签: javascript html css