dongyu2764 2011-05-17 03:39
浏览 33
已采纳

自动选择下拉值

i have an dropdown like this:

<select id="cbvms" name="cbvms" class="SelectList">
        <?php
        foreach($vm_array as $key => $value)
        {
            if(strcmp($vmguid,$key) == 0)
                echo "<option value=\"".$key."\" selected=\"".$value."\">".$value."</option>";
            else
                //echo "<option value=\"".$key."\">".$value."</option>";
                echo "<option value=\"".$key."\" title=\"".$value."\">".$value."</option>";
        }
        ?>
        </select>
    and in my database i have an option value like this ....

VM name:

 172.125.4.186
 172.125.4.101
 172.125.4.194
 172.125.4.126
 172.125.4.167
 172.125.4.102
 172.125.4.171
 172.125.4.118
 172.125.4.169
 Microsoft Windows Server 2003 Enterprise x64 Edition 5.2.3790 xen - 121 - centos 5.4 - ip 101
 salman
 saman
 172.125.4.198
 172.125.4.200
 172.125.4.189
 172.125.4.191

now i want when some one select any option value as shown as above my dropdown autosize

for example: when user select 172.125.4.169 then its fit on the size of dropdown, or when the user select "Microsoft Windows Server 2003 Enterprise x64 Edition 5.2.3790 xen - 121 - centos 5.4 - ip 101" then its also fit on the dropdown.

Right now if the VM name is long, the drop down field for Select VM goes out of range....

  • 写回答

3条回答 默认 最新

  • doudao0660 2011-05-17 07:14
    关注

    u need to use jquery for this

     if ($.browser.msie) $('select.SelectList')
                        .bind('focus mouseover', function() { $(this).addClass('expand').removeClass('clicked'); })
                        .bind('click', function() { $(this).toggleClass('clicked'); })
                        .bind('mouseout', function() { if (!$(this).hasClass('clicked')) { $(this).removeClass('expand'); }})
                        .bind('blur', function() { $(this).removeClass('expand clicked'); });
    

    CSS:

     select {
                    width: 120px; /* Or whatever width you want. */
                }
                select.expand {
                    width: auto;
                }
    

    All you need to do is to add the class SelectList to the dropdown element(s) in question.

    <select id="cbvms" name="cbvms" class="SelectList">
    <?php
            foreach($vm_array as $key => $value)
            {
                if(strcmp($vmguid,$key) == 0)
                    echo "<option value=\"".$key."\" selected>".$value."</option>";
                else
                    echo "<option value=\"".$key."\" title=\"".$value."\">".$value."</option>";
            }
            ?>
            </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况