Facing weird problem while adding and removing class

前端 未结 2 1126
深忆病人
深忆病人 2021-01-24 13:16


i have below function which is being used to initialize a widget.

jQuery.fn.initPortlet = function( parent_component ,header , component ){
        var o         


        
2条回答
  •  故里飘歌
    2021-01-24 13:37

    Not sure what variable o is being used for - but the general point of my alteration below is to check to see if the class has been applied already, using the jQuery hasClass() function.

    jQuery.fn.initPortlet = function( parent_component ,header , component ){
        var o = $(this[0])
    
        if (!this.hasClass('ui-widget'))
        {
          this.addClass("ui-widget ui-widget-content ui-corner-all")
            .find(header)           
            .addClass("headertitle")
            .addClass("align_center")
            .addClass("defaultheadercolor")
            .prepend('')
            .end()
            .find(component);
        }
    };
    

提交回复
热议问题