将以下国家/地区选项列表和显示的文本大写;
<select id="countrySelect"..>
<option value="SG">Singapore</option>
<option value="JP">Japan</option>
...
</select>
那些所有展示文字怎么能像 SINGAPORE , JAPAN 等那样难以理解?
赞赏任何JQuery
或CSS
方式,哪一方更好?
答案 0 :(得分:4)
使用CSS:
#countrySelect {
text-transform:uppercase;
}
CSS解决方案更好,因为浏览器会为您完成所有工作。
答案 1 :(得分:1)
使用Jquery,您可以使用.text()
或.html()
及其回调函数来设置大写值:
$('#countrySelect option').text(function(i,oldtext){
return oldtext.toUpperCase();
});
<强> Working Demo 强>
答案 2 :(得分:1)
如果你想让jQuery使用toUpperCase()
$('#countrySelect option').each(function(){
$(this).text($(this).text().toUpperCase());
});
答案 3 :(得分:0)
使用css
#countrySelect {text-transform:uppercase;}
答案 4 :(得分:0)
如果需要,可以使用jQuery大写css:
$(document).ready(function() {
$('#countrySelect').css('text-transform','uppercase');
});