http://www.5acode.com/show-83-18076.html

在mtom18988自己的webbrowser中的style动态修改后怎么立即生效

www.5acode.com   浏览:459次
 
<html> <body> <head> <style> .div{border:1solidgreen;} .ddd{color:red;width:1px;} </style> </head> </body> </html> 如上面所示,<style></style>标签内的东东动态修改(添加,删除,修改)后怎么立即生效?不要通过刷新页面,怎么做? 我试过动态修改再写入新内容引用新的设置(没用刷新,也不想用刷新),但是并没有生效。 
---------------------解决方案------------------------------

---------------------解决方案------------------------------
无论怎样,都需要排除缓存影响,刷新页面

当然你改变css可以是脚本控制

比如
<!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>无标题文档</title>
<style>
.box{width:100px;height:100px;background:red;}

.box1{width:200px;height:200px;background:green;}
</style>
<script>
window.onload=function()
{
var oBtn=document.getElementById('btn');
var oBox=document.getElementById('box');
oBtn.onclick=function(){
oBox.className='box1'
}
}
</script>
</head>


<body>
<div class="box" id="box">
</div>
<input type="button" value="样式改变" id="btn"/>
</body>
</html>

---------------------解决方案------------------------------
楼上的,我要改变的不是classname而是某个classname所包含的的内容。
<html>
<body>
<head>
<style>
 .div{border:1 solid green;}
 .ddd{color:red;width:1px;}
</style>
</head>
<div id=div1 class="div"></div>
<div id=div2 class="div"></div>
<div id=div3 class="div"></div>
....
<div id=divn class="div"></div>

</body>
</html>

动态修改div1~divn的边框样式,我可以这样做:
for i=1 to n
    wb.document.all.item("div" & i).style.border="1 dashed red"
next
我不想这么做,更想通过改变style中的css来达到目的,如:
<style>
 .div{border:1 dashed red;}
 .ddd{color:red;width:1px;}
</style>
现在问题是怎么让它立即生效..... 
---------------------解决方案------------------------------
该回复于2014-03-30 17:13:42被管理员删除 
---------------------解决方案------------------------------
不好意思,解决了。原来修改方法有误,所以失败了。