禁用IE6和IE7中的下拉问题

时间:2010-09-27 14:29:31

标签: internet-explorer-6 html-select

我在下拉框中显示类别和子类别,我不希望任何用户选择主类别的下拉值。

所以我应用了disable="disabled",它在Firefox,Chrome和IE8中运行良好,但它在IE6和IE7中无效。

我的代码:

<option value="test" disabled="disabled" >Test></option>

3 个答案:

答案 0 :(得分:2)

IE6 / IE7似乎是一个记录良好的问题。

Google快速搜索显示了这种潜在的解决方法: http://www.goodercode.com/wp/disable-select-options-internet-explorer-jquery/

答案 1 :(得分:0)

我认为你不能在IE中实现这一目标。你可以做的是使用一些小的javascript告诉用户该选项被禁用:

function check(el) {
  if (el.options[el.selectedIndex].disabled) {
     alert ("This option is not available!")
     el.options.value = '';
  }
}

同时检查此解决方案:http://www.lattimore.id.au/2005/07/01/select-option-disabled-and-the-javascript-solution/

答案 2 :(得分:0)

您可以将“类别”和“子类别”放入<optgroup>,如下所示:

<select>
  <optgroup label="Category"></optgroup>
</select>

<select>
  <optgroup label="Category">
    <option>Category 1</option>
    <option>Category 2</option>
  </optgroup>
</select>
IE5.5支持

有关详细信息,请参阅http://reference.sitepoint.com/html/optgroup