通过CSS设置选定的选项? [英] Set selected option via CSS?

查看:68
本文介绍了通过CSS设置选定的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过CSS类设置option标记的selected属性?

Is it possible to set the selected attribute of an option tag via a CSS class?

我想知道样式表中是否可能存在以下内容:

I'm wondering if something like the following is possible in a stylesheet:

option.selected {
  selected: true;
}

然后使用HTML:

<option class="selected">

与设置selected属性具有相同的效果.这种技术可行吗?

Which would have the same effect as setting the selected attribute. Is this technique possible?

推荐答案

不,CSS仅更改表示形式,而不更改内容(尽管CSS3确实支持内容的某些修改,但不支持值的选择.)您将需要如果无法直接修改HTML,则使用JavaScript.

Nope, CSS only alters the presentation, not the content (although CSS3 does support some modification of content, but not the selection of values.) You'll need to use JavaScript if you can't modify the HTML directly.

这篇关于通过CSS设置选定的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆