Javascript jQuery$.removeAttr(";selected";)更改所选选项

Javascript jQuery$.removeAttr(";selected";)更改所选选项,javascript,jquery,Javascript,Jquery,请看一个例子: 正如您所看到的,两个选择器之间的区别只是行 $("#chooser-1 .y").removeAttr("selected"); 但结果是它们的状态不同(尤其是在铬中)。 是我遗漏了什么,还是它是一个bug?看起来像是带有属性的jQuery的内部bug 请注意,在旧版本中,在1.6版本中引入.prop()之前,它是 在较新版本中,只需使用.prop()来处理元素的此类属性: $("#chooser-1 .x").prop("selected", "selected"); $("

请看一个例子:

正如您所看到的,两个选择器之间的区别只是行

$("#chooser-1 .y").removeAttr("selected");
但结果是它们的状态不同(尤其是在铬中)。
是我遗漏了什么,还是它是一个bug?

看起来像是带有属性的jQuery的内部bug

请注意,在旧版本中,在1.6版本中引入
.prop()
之前,它是

在较新版本中,只需使用
.prop()
来处理元素的此类属性:

$("#chooser-1 .x").prop("selected", "selected");
$("#chooser-1 .y").removeProp("selected");


更重要的是,在先前使用
prop()
选择的元素上使用
.removeProp(“selected”)
将导致返回原始选择,而不是什么都没有选择-理想的行为。

我发现上面的答案也失败了,我必须将prop设置为false以使所选项目不被选中

$("#chooser-1 .x").prop("selected", false);
removeProp会导致不希望出现的效果,例如无法再次重新选择选项


我使用jquery 1.6.2

,虽然它可以工作,但是prop()在html选项元素中没有设置selected属性,所以我使用这两个属性{.removeProp('selected').removeAttr('selected')}和{.prop('selected','selected').attr('selected','selected')}