返回到:Prototype – 元素对象
此方法返回元素的给定 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 – 元素对象
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9098.html
支付宝
微信