如何用JS修改DIV中文字的颜色或其它样式

这是一个简单的日历提醒,鼠标碰到那个月份,那个月份的方格的颜色就会变成白色;我还想让碰到方框里面的文字的颜色也发生改变,比如说碰到的同时,文字颜色变成了红色;下面是原程序语言,求大神能帮我解答一下应该怎么解决:

(以上部分删除)
——————————————————————————————————————————————
<script>
window.onload=function()
{
var oDiv=document.getElementById('div1');
var oBox=oDiv.getElementsByTagName('div');

var btn = null;

for(var i=0;i<oBox.length;i++)
{

oBox[i].onmouseover=function()
{

if(btn != null)
{
btn.style.backgroundColor = "";
}
btn = this;
this.style.backgroundColor = "white";
}

}
}
</script>

</head>
<body>
<div id="div1">
<div class="box" "type="button"><h1>1</h1><p>JUN</p></div>
<div class="box" "type="button"><h1>2</h1><p>FEB</p></div>
<div class="box" "type="button"><h1>3</h1><p>MAR</p></div>
<div class="box" "type="button"><h1>4</h1><p>APR</p></div>
<div class="box" "type="button"><h1>5</h1><p>MAY</p></div>
<div class="box" "type="button"><h1>6</h1><p>JUN</p></div>
<div class="box" "type="button"><h1>7</h1><p>JULY</p></div>
<div class="box" "type="button"><h1>8</h1><p>AUG</p></div>
<div class="box" "type="button"><h1>9</h1><p>SEP</p></div>
<div class="box" "type="button"><h1>10</h1><p>OCT</p></div>
<div class="box" "type="button"><h1>11</h1><p>NOV</p></div>
<div class="box" "type="button"><h1>12</h1><p>DEC</p></div>
<input class="footer" "type="text" />
</div>

</body>
</html>

<script>
window.onload=function()
{
var oDiv=document.getElementById('div1');
var oBox=oDiv.getElementsByTagName('div');

var btn = null;

for(var i=0;i<oBox.length;i++)
{
oBox[i].onmouseover=function()

if(btn != null)
{
btn.style.backgroundColor = "";
btn.getElementsByTagName("h1")[0].style.color = "";
}
btn = this;
this.style.backgroundColor = "white";
this.getElementsByTagName("h1")[0].style.color = "red";
}
}
}
</script>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-04-01
123456789101112131415161718192021222324<script>window.onload=function(){ var oDiv=document.getElementById('div1'); var oBox=oDiv.getElementsByTagName('div'); var btn = null; for(var i=0;i<oBox.length;i++) { oBox[i].onmouseover=function() { if(btn != null) { btn.style.backgroundColor = ""; btn.getElementsByTagName("h1")[0].style.color = ""; } btn = this; this.style.backgroundColor = "white"; this.getElementsByTagName("h1")[0].style.color = "red"; } }}</script>
相似回答