level 8
<html>
<title>无标题文档</title>
<style>
.ww{
background-color:#FF0000;
}
</style>
<body>
<input type="button" value="点击显示窗体1" onClick="func()" />
<div id="wd" style="width:100px; height:100px; background-color:#999999 ">我是窗口1</div>
<script>
function func()
{
wd.className="ww"
}
</script>
</body>
</html>
代码如上,我在WD这个ID里定义了一个背景颜色,但是用className做点击时间无法覆盖这个CSS。把 background-color:#999999删掉就可以运行了 ,或者把方法改成wd.style.background="#ff0000"; 也可以运行,请问是为什么?
2012年02月23日 06点02分
1
level 5
document.getElementById()
2012年02月23日 06点02分
2
level 8
试过了不行,不可以覆盖 代码如下
<html>
<title>无标题文档</title>
<style>
.ww{
background-color:#FF0000;
}
</style>
<body>
<input type="button" value="点击显示窗体1" onClick="func()" />
<div id="wd" style="width:100px; height:100px; background-color:#999999 ">我是窗口1</div>
<script>
function func()
{
document.getElementById('wd').className='ww';
}
</script>
</body>
</html>
2012年02月23日 06点02分
3
level 5
是样式的优先级问题
<div id="wd" style="width:100px; height:100px; background-color:#999999 ">
内部样式 > 行样式 > 外部样式
代码改成这样
<html>
<title>无标题文档</title>
<style>
div {
background-color:#999999
}
div.ww {
background-color:#FF0000;
}
</style>
<body>
<input type="button" value="点击显示窗体1" onclick="func()" />
<div id="wd" style="width:100px; height:100px;">我是窗口1</div>
<script>
function func(){
document.getElementById('wd').className='ww';
}
</script>
</body>
</html>
2012年02月23日 08点02分
4
level 8
内部样式是指最上面
<style></style>里
外部样式可以理解为<div style=""></div>
这样吗?
请问行样式是什么啊?
2012年02月23日 08点02分
5
level 8
不对 按照你的写法因该是
内部样式是指<div style=""></div>
外部样式指最上面的<style></style>
可是还是不懂行样式。。
2012年02月23日 08点02分
6
level 6
行 <div style=""></div>
内部 <style></style>
外部<link>
优先级是从高到低的....
<div id="wd" style="width:100px; height:100px; background-color:#999999 ">我是窗口1</div>
像这样写 优先级就是最高的....
2012年02月23日 08点02分
7
level 5
我的说法有错 ,正确说法在下面:
一般而言,所有的样式会根据下面的规则层叠于一个新的虚拟样式表中,其中数字 4 拥有最高的优先权。
1.浏览器缺省设置
2.外部样式表
3.内部样式表(位于 <head> 标签内部)
4.内联样式(在 HTML 元素内部)
2012年02月23日 09点02分
9
level 5
好的,我也明白了~~~~~~~~~~~~~~~~~~~!!!!!
2012年02月23日 11点02分
11