天天看點

jQuery擷取或設定元素的寬度和高度

jQuery擷取或設定元素的寬度和高度:

可使用以下3種方法:

1,jQuery width() 和 height() 方法;

2,innerWidth() 和 innerHeight() 方法;

3,outerWidth() 和 outerHeight()方法。

jQuery width() 和 height() 方法,innerWidth() 和 innerHeight() 方法,outerWidth() 和 outerHeight() 方法的差別如下:

一、jQuery width() 和 height() 方法

width() 方法設定或傳回元素的寬度(不包括内邊距、邊框或外邊距)。

height() 方法設定或傳回元素的高度(不包括内邊距、邊框或外邊距)。

二、jQuery innerWidth() 和 innerHeight() 方法

innerWidth() 方法設定或傳回元素的寬度(包括内邊距)。

innerHeight() 方法設定或傳回元素的高度(包括内邊距)。

三、jQuery outerWidth() 和 outerHeight() 方法

outerWidth() 方法設定或傳回元素的寬度(包括内邊距和邊框)。

outerHeight() 方法設定或傳回元素的高度(包括内邊距和邊框)。

我愛代碼,代碼使我快樂!