1

我想以select option粗体显示 a 的文本,如下图所示。该代码在除 Chrome 之外的所有浏览器中运行良好。我怎么解决这个问题?

<select style="font-weight:normal">
  <option style="font-weight:bold">Bold text here</option>
  <option style="font-weight:bold">Bold text here</option>
  <option style="font-weight:bold">Bold text here</option>
  <option style="font-weight:bold">Bold text here</option>
</select>

4

2 回答 2

2

基本思路是这样的

<div id="list1" class="dropdown-check-list">
        <span class="anchor">Select Fruits</span>
        <ul class="items">
            <li><b>Apple</b></li>
            <li>Orange</li>
            <li>Grapes </li>
            <li>Berry </li>
            <li>Mango </li>
            <li>Banana </li>
        </ul>
    </div>

css

.dropdown-check-list {
  display: inline-block;
}
.dropdown-check-list .anchor {
  position: relative;
  cursor: pointer;
  display: inline-block;
  padding: 5px 50px 5px 10px;
  border: 1px solid #ccc;
}
.dropdown-check-list .anchor:after {
  position: absolute;
  content: "";
  border-left: 2px solid black;
  border-top: 2px solid black;
  padding: 5px;
  right: 10px;
  top: 20%;
  -moz-transform: rotate(-135deg);
  -ms-transform: rotate(-135deg);
  -o-transform: rotate(-135deg);
  -webkit-transform: rotate(-135deg);
  transform: rotate(-135deg);
}
.dropdown-check-list .anchor:active:after {
  right: 8px;
  top: 21%;
}
.dropdown-check-list ul.items {
  padding: 2px;
  display: none;
  margin: 0;
  border: 1px solid #ccc;
  border-top: none;
}
.dropdown-check-list ul.items li {
  list-style: none;
}
.dropdown-check-list.visible .anchor {
  color: #0094ff;
}
.dropdown-check-list.visible .items {
  display: block;
}

脚本

<script type="text/javascript">

        var checkList = document.getElementById('list1');
        checkList.getElementsByClassName('anchor')[0].onclick = function (evt) {
            if (checkList.classList.contains('visible'))
                checkList.classList.remove('visible');
            else
                checkList.classList.add('visible');
        }

    </script>

这会让你开始。这使用最少的 javascript。你可以做的更多。摆弄和实验。

于 2013-10-07T12:58:10.863 回答
1

可以给我们更多关于你需要什么的信息吗?

例如:如果您需要将所选选项加粗,我使用了这样的技巧,当您选择一个选项时,它会变为粗体:

小提琴:http: //jsfiddle.net/Gt7Yq/

html:

<select>
    <optgroup id='111' label="111" style="display:none"></optgroup>
    <option value="111">111</option> 
    <optgroup id='222' label="222" style="display:none"></optgroup>
    <option value="222">222</option> 
</select>

js:

$('select').on('change',function(){
    $('optgroup').hide();
    $('select option').show();
    $('select option:selected').hide();
    $('#'+$('select option:selected').val() ).show();
});

但是如果你想显示一个特殊的选项,即使它没有被选中......我无法帮助你......(但答案让我很感兴趣)

于 2013-10-07T12:57:03.960 回答