增加下拉列表的宽度

增加下拉列表的宽度

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

问题描述

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

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...

推荐答案

<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()"



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

05-23 00:17