如何将下拉菜单的选定值单独显示为大写? [英] How to display selected value of a dropdown alone in uppercase?

查看:125
本文介绍了如何将下拉菜单的选定值单独显示为大写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在小型案例中显示下拉列表的所有其他选项,但所选的一个。所选择的应以大写形式显示。

I want to display all other options of a dropdown in small case, except The selected one. Selected one should be displayed in uppercase.

select{
  text-transform: uppercase;
}
option{
  text-transform: lowercase !important;
}

我认为我们不能样式选项元素。除了自定义下拉菜单之外还有其他选择吗?

I think, we cannot style option elements. Is there any other alternatives other than a custom drop-down?

它在ipad工作正常,因为ipad的默认行为与我的期望相同。

It's working fine in ipad since ipad's default behaviour is same as my expectation. But it's not fine in android.

您可以在此处看到下拉菜单小提琴

You can see the dropdown in this fiddle.

推荐答案

您可以使用jQuery text() 函数:

You can use jQuery text() function :

$("select").change(function () {
   $(this).find("option").text(function (i, text) {
        return $(this).is(":selected") ?  text.toUpperCase() : text.toLowerCase()
   });
}).trigger("change");

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
    <option>One</option>
    <option>Two</option>
</select>

这篇关于如何将下拉菜单的选定值单独显示为大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆