gpt4 book ai didi

javascript - jQuery 3.0 removeAttr 与 prop

转载 作者:行者123 更新时间:2023-12-02 14:31:28 26 4
gpt4 key购买 nike

我刚刚读到了 jQuery 3.0 的重大变化,我想所有前端工程师都应该知道这一点。

例如问题,1. 如何取消选中复选框?2. 如何去掉单选按钮的勾选?

$('input').prop('checked', false);

最佳答案

It is almost always a mistake to use .removeAttr( "checked" ) on a DOM element. The only time it might be useful is if the DOM is later going to be serialized back to an HTML string. In all other cases, .prop( "checked", false ) should be used instead.

https://jquery.com/upgrade-guide/3.0/#feature-new-signature-for-jquery-get-and-jquery-post

关于javascript - jQuery 3.0 removeAttr 与 prop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37771034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com