重现错误:http://jsfiddle.net/rkw79/mmBKf/2/
>在列表框中选择一个项目
>点击UL中的该项目,它将消失,列表框将显示为未选中
>单击列表框中的相同项目
请注意,事件已触发,但未添加该项
现在执行相同的步骤,除了使用.prop(‘selected’,”)而不是.removeProp(‘selected’):http://jsfiddle.net/rkw79/mmBKf/3/
解决方法
With some built-in properties of a DOM element or window object,browsers may generate an error if an attempt is made to remove the property. jQuery first assigns the value undefined to the property and ignores any error the browser generates. In general,it is only necessary to remove custom properties that have been set on an object,and not built-in (native) properties.
Note: Do not use this method to remove native properties such as checked,disabled,or selected. This will remove the property completely and,once removed,cannot be added again to element. Use
.prop()
to set these properties tofalse
instead.