修改JQuery對象的樣式和內容:
阿新 • • 發佈:2017-07-29
外邊距 jquery對象 turn 邊距 集合 沒有 class pos eight
添加或修改class:addClass(name);
- 移除類:removeClass(name);
- 以上方法可以定義函數,不過返回值需要有一個或多個類名。
$(‘#demo‘).addClass(function(index,className){ return ‘red‘; })
-
- 判斷是否有某個類:hasClass(name);
- 切換某個類,有就刪除,沒有就添加:toggleClass(name);
- 獲取或設置style (用橫杠寫屬性需要加引號,駝峰則不用):css(name,value);
- 設置不包含邊框和內邊距寬和高:width()和height();
- 設置包含內邊距的高:innerHeight();
- 設置包含內邊距和邊框的高,可以設置值為true的話包含外邊距:outerHeight();
- 返回對象集合中的一個元素,返回兩個值,左側和頂部的距離:offset();
- 返回匹配元素相對於父元素的位置(偏移):position();
- 設置滾動條:scrollTop()和scrollLeft();
- 設置內容:html()設置html的值,只獲取集合的的一個,text()設置文本,集合獲取全部值。
修改JQuery對象的樣式和內容: