- Prototype 教程
- Prototype - 主頁
- Prototype - 簡要概述
- Prototype - 有用功能
- Prototype - 實用方法
- Prototype - 元素物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - 雜湊處理
- Prototype - 基本物件
- Prototype - 模板化
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - 表達範圍
- Prototype - 經常執行
- Prototype 有用資源
- Prototype - 指南
- Prototype - 實用資源
- Prototype - 討論
Prototype - getDimensions() 方法
此方法查詢元素的計算寬度和高度,並將其作為物件的鍵/值對返回。
此方法將針對 display 在內聯樣式規則或 CSS 樣式表中均設定為 none 的元素返回正確的值。
請注意,雖然結果以畫素表示,但所返回的值是一個數字。
語法
element.getDimensions();
返回值
其返回物件 {height: number, width: number} 的鍵/值對。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var dimensions = $('rectangle').getDimensions();
alert("Element width is " + dimensions.width );
alert("Element height is " + dimensions.height );
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<div id = "rectangle"
style = "font-size: 10px; width: 20em; height: 10em">
<p>This is the paragraph.</p>
</div>
<br />
<input type = "button" value = "showResult" onclick = "showResult();"/>
</body>
</html>
輸出
prototype_element_object.htm
廣告