如何从css中了解是否打开了选择

时间:2015-05-26 08:25:11

标签: html css

有没有办法在css中知道是否打开了选择?我想在打开我的选择时更改下拉图像。

2 个答案:

答案 0 :(得分:1)

您可以知道选择是否已集中

select:focus {}

大多数情况下,这表明它是开放的,但并非总是如此。要100%确定它,你需要javascript。

我希望它有所帮助。

答案 1 :(得分:0)

你可以使用bootstrap类型的drop down来实现。在你的项目中包含bootstrap css和js文件

步骤1 - 创建下拉列表,如下所示。

<div id="ddl" class="dropup">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-expanded="true">
    Dropdown
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu2">
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
  </ul>
</div>

Step2-现在,对于该div,您可以指定一种toogle类型的事件。

$('#ddl').toogle({
if(class='dropup')
{
//Here  assign a class to the div(dropup or drop down )
}
else
{
//Here  assign a class to the div(dropup or drop down )
}
});