jQuery獲取或設置元素的寬度和高度:
可使用以下3種方法:
1,jQuery width() 和 height() 方法;
2,innerWidth() 和 innerHeight() 方法;
3,outerWidth() 和 outerHeight()方法。
jQuery width() 和 height() 方法,innerWidth() 和 innerHeight() 方法,outerWidth() 和 outerHeight() 方法的區別如下:
一、jQuery width() 和 height() 方法
width() 方法設置或返回元素的寬度(不包括內邊距、邊框或外邊距)。
height() 方法設置或返回元素的高度(不包括內邊距、邊框或外邊距)。
width() 方法設置或返回元素的寬度(不包括內邊距、邊框或外邊距)。
height() 方法設置或返回元素的高度(不包括內邊距、邊框或外邊距)。
二、jQuery innerWidth() 和 innerHeight() 方法
innerWidth() 方法設置或返回元素的寬度(包括內邊距)。
innerHeight() 方法設置或返回元素的高度(包括內邊距)。
innerWidth() 方法設置或返回元素的寬度(包括內邊距)。
innerHeight() 方法設置或返回元素的高度(包括內邊距)。
三、jQuery outerWidth() 和 outerHeight() 方法
outerWidth() 方法設置或返回元素的寬度(包括內邊距和邊框)。
outerHeight() 方法設置或返回元素的高度(包括內邊距和邊框)。
outerWidth() 方法設置或返回元素的寬度(包括內邊距和邊框)。
outerHeight() 方法設置或返回元素的高度(包括內邊距和邊框)。