码迷,mamicode.com
首页 > Web开发 > 详细

智能社js学习笔记

时间:2015-05-12 15:20:14      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

style.height书写方式与style[height]  书写等价 即.可与[]互换

可以用.的地方也可以用[],但是[]更好的地方在于可以用在函数传参

<script type="text/javascript">
function to(name,num){
    var to=document.getElementById(‘div1‘);
    to.style[name]=num;
     }
</script>

</head>
<body>
    <button   onclick="to(‘backgroundColor‘,‘red‘)">变红</button>
    <button onclick="to(‘height‘,‘400px‘)">变高</button>
<div id="div1">
</div>
</body>

style加样式是在行间添加,取样式也是在行间取,如果样式写在外部文件,则style无效

智能社js学习笔记

标签:

原文地址:http://www.cnblogs.com/wyy725872/p/4497209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!