如何用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 = 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> 展开
2个回答
展开全部
<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>
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>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询