- 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 - 討論
原型 - getStyle() 方法
此方法返回元素的給定 CSS 屬性值。屬性可以採用 CSS 或駝峰命名形式。
所以提供 font-size 和 fontSize 等效。
語法
element.getStyle( property );
返回值
如果找不到屬性集則返回 CSS 屬性值或者 NULL。Internet Explorer 返回字面值,而其他瀏覽器返回計算值。如果元素處於隱藏狀態,Safari 將為任何非內聯屬性返回 null。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var str = $('grandfather').getStyle('margin-left');
alert("Element left margin is : " + str );
}
</script>
<style>
#grandfather {
font-size: 12px;
margin-left: 1em;
}
</style>
</head>
<body>
<p>Click the button to see the result.</p>
<div id = "grandfather">This is grand father
<div id = "father"> This is father.
<div id = "kid">This is kid</div>
</div>
</div>
<br />
<input type = "button" value = "showResult" onclick = "showResult();"/>
</body>
</html>
輸出
prototype_element_object.htm
廣告