选择下拉宽度 - Chrome问题 [英] Select drop down width - Chrome issue

查看:146
本文介绍了选择下拉宽度 - Chrome问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想控制< option> 列表宽度< select> 下拉菜单。默认情况下,浏览器会在< option> 中计算较大的文本,并下载accommodes。网站看起来不好看我尝试过以下CSS代码段,并发现在FF中工作。

I would like to control <option> list width of <select> drop down. By default, browser calculates larger text in the <option> and accommodes drop down. It doesn't look good in sites. I had tried the following CSS snippet and found working in FF.

select{
    width : 120px;
}
select option {
    width : 90px;
}

唯一麻烦的是causer是Chrome。如果有任何解决方法,可以让我知道。

The only trouble causer is Chrome. Could u let me know if any workarounds.

演示

推荐答案

Google搜索结果并不适用于我。我只剩下脚本选项。以下代码实现了一切。

Googling it didn't turn out for me. I've only script option left out. The following code does the trick..

/* To trim the charaters in the option list */
    var optLen = $('#country option').size();
    //console.log("Total length is :" +optLen);
    for(var i=0; i<optLen; i++){
        var txt = $('#country option').eq(i).text();
        //alert(txt);
        txt = txt.substring(0,20);
        //alert(txt);
        $('#country option').eq(i).text(txt);
    }

更新演示

这篇关于选择下拉宽度 - Chrome问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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