jquery - jQuery 中的 .removeProp() 是否存在错误,或者我做错了什么?

标签 jquery

列表框中选定的项目将显示在下面的 UL 中。单击 UL 中的某个项目,它会将其从列表框中删除,并将其自身从 UL 中删除。

重现错误:http://jsfiddle.net/rkw79/mmBKf/2/

  • 在列表框中选择一个项目
  • 点击 UL 中的该项目,它将消失,并且列表框会将其显示为未选中
  • 单击列表框中的同一项目

请注意,事件已触发,但未添加项目

现在执行相同的步骤,但使用 .prop('selected','') 而不是 .removeProp('selected'): http://jsfiddle.net/rkw79/mmBKf/3/

最佳答案

您需要知道的一切是 in the documentation .

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 to false instead.

关于jquery - jQuery 中的 .removeProp() 是否存在错误,或者我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8440640/

相关文章:

javascript - 我简单的 jquery 下拉功能有问题和故障

javascript - 在 Pyppeteer (Python Puppeteer) 中通过文本选择按钮

javascript - boxslider 插件在 sitecore 预览模式下不工作

jquery - 在 jQuery 中获取选项的 attr

javascript - 如何将事件类添加到基于每个页面中的 URL 的导航菜单

javascript - 如何在 php 中使用内联 jquery

javascript - 我如何解决 Typescript 构建中的错误 "cannot find module ' jquery'"

jquery - 语义UI自定义allowAdditions消息

javascript - 下拉隐藏在 jquery slider 后面

jquery - Kendo UI Mobile - 在 JQuery 中删除时,CSS 属性会在 View 转换时重置