Javascript选项部分斜体
我想使我的HTML选项的第一个字斜体,但只有在下拉菜单中的文本更改,所选项目保持正常字体Javascript选项部分斜体,javascript,html,drop-down-menu,Javascript,Html,Drop Down Menu,我想使我的HTML选项的第一个字斜体,但只有在下拉菜单中的文本更改,所选项目保持正常字体 <select name="selectGene" id="selectGene"> <option value="gene"> Homo sapiens BCL3 </option> </select> <script> var opt = document.getElementById("selectGene").optio
<select name="selectGene" id="selectGene">
<option value="gene"> Homo sapiens BCL3 </option>
</select>
<script>
var opt = document.getElementById("selectGene").options[0];
var str = "Homo sapiens"
opt.innerHTML = str.italics() + " BCL3";
</script>
智人BCL3
var opt=document.getElementById(“selectGene”).options[0];
var str=“智人”
opt.innerHTML=str.italics()+“BCL3”;
可能是这样,这对您很有用
<select name="selectGene" id="selectGene">
<option value="gene"> Homo sapiens BCL3 </option>
<option value="gene"> Homo sapiens BCL31 </option>
<option value="gene"> Homo sapiens BCL32 </option>
<option value="gene"> Homo sapiens BCL33 </option>
</select>
<script>
for(var i=0; i<document.getElementById("selectGene").options.length;i++){
var opt = document.getElementById("selectGene").options[i];
opt.style.fontStyle= "italic";
}
</script>
智人BCL3
智人BCL31
智人BCL32
智人BCL33
对于(var i=0;i您不能部分设置选项的样式,这些样式是所用平台的固有样式
下面的链接是jquery插件,它使用div和list元素来模拟select选项,您将能够应用您的样式
选项
元素只能包含文本内容,不能将其他HTML元素放入其中。