0

当我在选择下拉列表中更改选项时,我将选择的值传递给该特定选项..它在 chrome 和 FF 中工作正常。但它在 IE 中不起作用。

我通过 $('select option').removeAttr('selected'); $(this).attr("selected", "selected");

我在 jsfiddle http://jsfiddle.net/harshacharya/JyvUm/中传递示例

I am trying to do something like this: When an option is selected,it has attribute selected and other option dont. 上述功能在 IE 中不起作用。

你能帮帮我吗。谢谢。

4

1 回答 1

0

您似乎希望在 DOM 检查器中查看您的更改。默认情况下,IE 不会这样做(您不应该关心,因为幕后选择的值是正确的)。

但是,在 IE 中,您可以通过prop defaultSelected"selected". 然后,您将看到 DOM 中的视觉属性更改。

.prop("defaultSelected", "selected");

注意:要将其从其他元素中删除,您需要将 prop 设置为 null。

$(this).find('option').prop("defaultSelected", null);

JSFiddle:http: //jsfiddle.net/TrueBlueAussie/JyvUm/8/

于 2015-02-17T11:17:07.380 回答