javascript template

 

<html>
<head>
//当做模板使用,减少重复性的工作
<script language="javascript">
window.onload
=function(){
    alert($(
"div1").offsetHeight);
    alert($(
"div2").offsetHeight);
}
function $(id)
{
    
return document.getElementById(id);
}
</script>
</head>
<body>
<div id="div1" style = "position:absolute;300px;height:300px;margin-top:200px;background-color:red">
<div id="div2" style = "position:absolute;100px;height:200px;margin-top:50px;background-color:yellow;border:4px solid green;">
</div>
</div>
</body>
</html>

 

原文地址:https://www.cnblogs.com/applesuch5/p/2084430.html