根据所选值增加下拉列表的宽度. [英] Increase dropdownlist width according to selected value.

查看:97
本文介绍了根据所选值增加下拉列表的宽度.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法根据项目的长度来增加下拉列表的宽度.
我正在这样尝试..

I am not able to Increase dropdownlist width according to item length.
I am trying as like this..

<script type="text/javascript">
    function autoWidth()
    {
        var maxlength = 0;
        var mySelect = document.getElementById('Select1');
        for (var i=0; i<mySelect.options.length;i++)

        {

            if (mySelect[i].text.length > maxlength)
            {
                maxlength = mySelect[i].text.length;
            }
        }
        mySelect.style.width = maxlength * 10;
    }
</script>




但在Mozila无法正常运作.请帮助我...




but it is not working in mozila. Please help me...

推荐答案

尝试一下

Try this

<script type="text/javascript">
    function autoWidth()
    {
        var maxlength = 0;
        var mySelect = document.getElementById('Select1');
        for (var i=0; i<mySelect.options.length;i++)

        {

            if (mySelect[i].text.length > maxlength)
            {
                maxlength = mySelect[i].text.length;
            }
        }
        mySelect.style.width = maxlength * 10;
    }
</script>


并像这样使用它:onclick ="autoWidth()"


And use it like this: onclick="autoWidth()"


您的解决方案
Your solution here. (C#)

Hope this helps.


这篇关于根据所选值增加下拉列表的宽度.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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