JQuery獲取常用的尺寸屬性

2021-06-22 00:16:11 字數 1099 閱讀 6722

1.寬、高相關

函式名

說明例子

width()

獲取第乙個匹配元素的寬度,預設為px

$("#txt1").width()
width(val)

為匹配的元素設定寬度值,預設為px

$("#txt1").width(200)
height()

獲取第乙個匹配元素的高度,預設為px

$("#txt1").height()
height(val)

為匹配的元素設定寬度值,預設為px

$("#txt1").height(20)
innerwidth()

獲取第乙個匹配元素內部區域寬度(包括padding,不包括border)

$("#txt1").innerwidth()
innerheight()

獲取第乙個匹配元素內部區域高度(包括padding,不包括border)

$("#txt1").innerheight()
outerwidth([margin])

獲取第乙個匹配元素外部區域寬度(包括padding,border)

margin為true則包括margin,否則不包括

$("#txt1").outerwidth()
outerheight([margin])

獲取第乙個匹配元素外部區域高度(包括padding,border)

margin為true則包括margin,否則不包括

$("#txt1").outerheight(true)
注意:

返回的高度、寬度均為數字,不帶px

參照一張圖,會更容易理解些.

--選自《從零開始學習jquery》

javascript 常用尺寸屬性

offsetwidth 和 style.width 高度同理 的區別 offsetwidth 會獲取 元素本身的高度 padding border style.width會獲取 元素本身的高度 並且 style.width 只能獲取行內樣式 offsetwidth 返回數字style.width 返...

JQuery屬性獲取

操作物件標籤 web原生js屬性獲取 var div document.getelementbyid first 獲取第乙個標籤的id var divid div.id 給id重新賦值 div.id four 通過getattributr方法獲取屬性值 var divid div.getattrib...

幾個html常用取尺寸屬性

scrollleft 物件左邊界與物件當前可視左邊界之間距離 scrollwidth 物件可滾動寬度 scrolltop 物件上邊界與物件當前可視上邊界距離 scrollheight 物件可滾動高度 offsettop 物件距上邊界距離 offsetleft 物件距左邊界距離 offsetheigh...