开发者

Deselecting select options with jQuery needs scrolling to actually show

I have a somewhat odd problem deselecting options in a select using jQuery.

The code I have now (for selecting all):

$select.children().attr('selected', true);

This works fine.

For deselecting, I have tried various options:

$select.children().attr('selected', false);
$select.children().removeAttr('selected');
$select.find("option").attr('selected', false);
$select.find("option").each(function() {
   var $this = $(this);
   $this.removeAttr("selected");
});

etc.. and they all have the s开发者_JS百科ame problem (tested in chrome / safari). After I run the deselect code, I have to actually scroll before the options are shown as not selected.

Any ideas on how to fix this?

Regards, Morten


Try adding

$select.val(null);

Should revert the displayed value to be the first non-disabled option in the select.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜