gpt4 book ai didi

jquery - jQuery 中的 removeAttr(x) 与 attr(x, '' )

转载 作者:行者123 更新时间:2023-12-03 22:29:22 26 4
gpt4 key购买 nike

jQuery 中的 removeAttr(x)attr(x, '') 之间通常有区别吗?

如果是的话,什么时候使用每一个?

最佳答案

考虑到 jQuery 库中的 removeAttr 的定义(见下文)。我会说是的。

removeAttr: function( name, fn ) {
return this.each(function(){
jQuery.attr( this, name, "" );
if ( this.nodeType === 1 ) {
this.removeAttribute( name );
}
});

来源:Jquery 1.4.3 uncompressed version

尽管它本质上是主观的。我认为使用removeAttr是一种更加自记录的方法。然而,我可以看到其他人的想法相反。

关于jquery - jQuery 中的 removeAttr(x) 与 attr(x, '' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4217437/

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