语法:document.getElementById("id");
举例:<script>
window.onload = funtion ()
{
var oDiv = document.getElementById("div1");// js选择html元素id元素
oDiv.style.color = "red";//js控制html元素css样式color颜色;
}
<script>
<body>
<div id="div1">颜色被js控制更改红色<div>
</body>
时间: 2024-10-09 19:13:12