- 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
广告