JS 修改元素

var ele;
window.onload=function(){
    ele=document.createElement('div');
    ele.id='myEle1';
    ele.style.border='1px solid black';
    ele.style.height='20px';
    container=document.querySelector(".container");
    container.appendChild(ele);
    console.log(ele.style.height);
    setInterval(changeDIV,100);
}

function changeDIV(){
    //直接修改全局变量即可  //无需再querySelector一次
    ele.style.height= (parseInt(ele.style.height)+1)+'px';
}

 

posted @ 2014-05-24 16:20  cart55free99  阅读(130)  评论(0编辑  收藏  举报