2012年5月26日土曜日

[JQuery] IE8で select要素の選択を解除


$(’#mainform select option:selected’).attr(’selected’, false);
$(’#mainform select option’).attr(’selected’, false);
$(’#mainform select option’).removeAttr(’selected’);

 上記が、IEではうまく動作しない。


<対応>
↓以下のようにすると解除できる。


$(’#mainform select’).each(function() {
    this.selectedIndex  = 0;
});

(参考)