Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. CSS:层叠样式表
  3. CSS 参考
  4. 选择器
  5. :enabled

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

:enabled

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.

:enabledCSS伪类表示任何已启用的元素。如果元素可以被激活(例如被选择、单击、输入文本等),或者能够获得焦点,那么它就是启用的。该元素还有一个被禁用的状态,在此状态下它无法被激活或接受焦点。

尝试一下

label {  display: block;  margin-top: 1em;}*:enabled {  background-color: gold;}
<form>  <label for="name">Name:</label>  <input name="name" type="text" />  <label for="emp">Employed:</label>  <select name="emp" disabled>    <option>No</option>    <option>Yes</option>  </select>  <label for="empDate">Employment Date:</label>  <input name="empDate" type="date" disabled />  <label for="resume">Resume:</label>  <input name="resume" type="file" /></form>

语法

:enabled

示例

以下示例将在启用状态下把类型为文本输入框和按钮的<input> 颜色设置为绿色,禁用时设置为灰色。这有助于用户理解哪些元素可以进行交互操作。

HTML

html
<form action="url_of_form">  <label for="FirstField">第一个字段(已启用):</label>  <input type="text" value="Lorem" /><br />  <label for="SecondField">第一个字段(已禁用):</label>  <input type="text" value="Ipsum" disabled="disabled" /><br />  <input type="button" value="Submit" /></form>

CSS

css
input:enabled {  color: #2b2;}input:disabled {  color: #aaa;}

结果

规范

Specification
HTML
# selector-enabled
Selectors Level 4
# enabled-pseudo

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp