在select中添加class to option [英] add class to option in select
本文介绍了在select中添加class to option的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据选项的价值,可以在选项中添加一个类吗?
Based on the value of an option would that be possible to add a class to an option?
所以,如果我有这个:
<select class="rubrique" name="ctl00">
<option value="" selected="selected"></option>
<option value="1">1</option>
<option value="1">1</option>
</select>
我会得到:
<select class="rubrique" name="ctl00">
<option class="" value="" selected="selected"></option>
<option class="1" value="1">1</option>
<option class="2" value="1">1</option>
</select>
推荐答案
是的,非常轻松,使用<的回调签名a href =http://api.jquery.com/addClass/ =noreferrer> addClass
:
Yes, very easily, using the callback signature of addClass
:
$('.rubrique option').addClass(function() {
return this.value;
});
这篇关于在select中添加class to option的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文