代码之家  ›  专栏  ›  技术社区  ›  JochenJung

当下拉列表中的下拉列表更改其内容时,带有下拉列表的表在IE 7中不会调整大小

  •  1
  • JochenJung  · 技术社区  · 12 年前

    我的页面由一个包含两个下拉列表的表组成。当第一个下拉列表(组)发生更改时,第二个下拉列表将根据第一个选择获得新内容(JavaScript)。

    Process Monitor

    但是,在兼容性视图中的IE7和IE8中,第二个下拉列表不会调整表的大小。

    enter image description here

    这是我所期望的,也是它在其他浏览器中的样子(下拉列表扩展到其最大值的大小):

    enter image description here

    你知道我怎么能在IE7中得到同样的行为吗?

    这是代码:

    <table border="1" style="background-color: silver; margin: 0; padding: 0">
    <tr>
        <td style="background-color: #336; color: white; font-weight: bold">Process Monitor  </td>
    </tr>
    <tr><td>
        <table style="border: 0; margin: 0; padding: 0">
        <tr>
            <td width="10px">&nbsp;</td>
            <td><form name="rid_select" "action="?" method="GET">
                <select id="pvar_pri" name="pvar_pri" onChange="setOptions(this.options[this.selectedIndex].value)">
                    <option value="0">Select group</option>
                    <option value="5">Item 1</option>
                    <option value="10">Item 2</option>
                </select>
                <select id="pvar_sec" name="pvar_sec" onChange="this.form.submit()">
                    <option value="">Select variable</option>
                </select>
                <input type="submit" value="Select">
            </form></td>
            <td width="10px">&nbsp;</td>
        </tr>
        </table>
    </td>
    </tr></table>
    
    1 回复  |  直到 12 年前
        1
  •  1
  •   gotqn user3521065    12 年前

    我真的试图只使用CSS来解决这个问题,但仍然没有得到任何结果。

    我可以为您提供一个替代解决方案,因为您的表很小,重新绘制它不需要花费太多时间和资源:

    1. 添加包含表单的表的ID

      <table id="FormCointaner">
      
    2. 设置重新绘制表格的第一个选择框的onchange函数 每更改一个值

      $(document).on('change','#pvar_pri',function(){
          $('#FormCointaner').html($('#FormCointaner').html());
      });
      

    据我说,由于某种原因,当添加新元素时,IE不会重新绘制表格。

    你可以在这里查看我的想法:

    http://jsfiddle.net/jnKnx/