<script> var s1 = document.getElementById("id");//獲取ID var s2 = document.getElementsByTagName("div")//獲取標籤,陣列 var s3 = document.getElementsByClassName("class")//獲取class,陣列 var s4 = document.getElementsByName("name"); s1.style.marginLeft="100";//向左移動 s1.style.background="red";//背景色 for(var i = 0; i< s2.length;i++){ s2[i].style.background="blue"; } </script>
<script> var s1 = document.getElementById("id");//獲取ID var s2 = document.getElementsByTagName("div")//獲取標籤,陣列 var s3 = document.getElementsByClassName("class")//獲取class,陣列 var s4 = document.getElementsByName("name"); s1.style.marginLeft="100";//向左移動 s1.style.background="red";//背景色 for(var i = 0; i< s2.length;i++){ s2[i].style.background="blue"; } </script>