本文介绍了jQuery中的removeAttr(x)与attr(x,'')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery中的removeAttr(x)attr(x, '')通常是否存在区别?

Is there generally a difference between removeAttr(x) and attr(x, '') in jQuery?

如果是这样,什么时候使用每一个?

If so, when to use each one?

推荐答案

鉴于jQuery库中的removeAttr的定义(请参见下文).我会说.

Given that the defninition of removeAttr from the jQuery library (see below). I'd say yes.

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

来源: Jquery 1.4.3未压缩版本

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

Although it is inherently subjective. I think using removeAttr is a more self-documenting approach. However, I could see other people thinking the opposite.

这篇关于jQuery中的removeAttr(x)与attr(x,'')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 13:45