比如一个div中,有很多标签,怎么通过这个div来控制这些里面的元素呢?比如鼠标放上这个div,里面所有标签的字都变成白色?可以实现吗?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题 1</title>
<style type="text/css">
.red{
color:red
}
.write{ color:blue;}
</style>
</head>
<body>
<div id="div" onmouseover="color('red')" onmouseout="color('')"><span>A</span>
<span class="write">B</span>
<span>C</span>
<span>D</span>
</div>
<script type="text/javascript">
function color(c){
document.getElementById("div").className=c
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题 1</title>
<style type="text/css">
.red{
color:red
}
.write{ color:blue;}
</style>
</head>
<body>
<div id="div" onmouseover="color('red')" onmouseout="color('')"><span>A</span>
<span class="write">B</span>
<span>C</span>
<span>D</span>
</div>
<script type="text/javascript">
function color(c){
document.getElementById("div").className=c
}
</script>
</body>
</html>
解决方案 »
- jQuery的$.unique在失效了~~怎么回事?
- 请教高手!下面的代码哪里错了?
- 动态的添加Ext TabPanel时,为什么它的html不能直接显示,要点击一下才显示
- js怎样用下拉按钮选择图片
- DIV的位置交换问题??在线等。。
- 调用框架的另外HTM文件内容的语句语法有哪些地方错了,解决了马上给100分!
- 现在叉掉IE事件可以用onunload解决 可是别的异常退出呢?■■■最后10分■■■
- 一个全功能的web reports 控件,自己做了近一年,有兴趣的来看看.
- 如何动态生成层?因我生成层的数目是随机的,且数量很大
- 函数对象的简单问题
- ext textarea 换行问题
- 有一个带背景色的层在图片上时,图片onmousemove无效如何解决
原来是getElementById,
不是 getElementsById, 没有s。。囧,这处女贴发的!!!