在addClass()方法中有两种表示

第一种是直接添加类,如$("p:first").addClass("intro");

第二种是用函数添加类 必须用currentClass来包。用class不行

$("div").addClass(function(index, currentClass) {
            var addedClass;

            if ( currentClass === "red" ) {
                addedClass = "green";
                $("p").text("There is one green div");
            }
            return addedClass;

});

在append()方法中需注意

$("p").append(function(n,html){
      return "<b>This p element has index " + n + html+ "</b>";
});

attr()的用法有三

返回被选元素的属性值。 $("img").attr("width")

设置被选元素的属性和值。$("img").attr("width","180")  如果attr中要设置多了属性则如下 $("img").attr({width:"50",height:"80"});

使用函数来设置属性/值 第二个参数是当前值

$("img").attr("width",function(n, v){
           return v-50;
        });

相关文章:

  • 2021-09-13
  • 2021-08-07
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2021-11-25
  • 2021-12-08
  • 2022-03-09
  • 2021-12-24
  • 2022-12-23
相关资源
相似解决方案