js【封装】$id函数--方便获取dom中的id

<div id="dome">sdfsd</div>
<div id="test">gfdg</div>
function $(id) {
        return document.getElementById(id);
 }
$("dome").style.backgroundColor='red';
$("test").style.backgroundColor='pink';
function $(id) { return document.getElementById(id); }

此方法就是封装了一个$()函数,可以方便获取dom中的id。

 

posted @ 2017-03-07 17:06  Shimily  阅读(818)  评论(0)    收藏  举报