为什么鼠标放上去后闪烁个不停?

WiseNeuro 2006-05-26 03:29:00
我写了个html:
<html>
<head><title>Design Menu</title></head>
<script language="javascript" type="text/javascript">
var flag = 0;
function ChangeView(id){
var node_element = document.getElementById(id);
if(id){
if(flag == 0){
node_element.innerHTML = "<font style='background-color: #80ff00'>Menu Item1</font>" ;
flag = 1;
}
}
}
function Recover(id){
var node_element = document.getElementById(id);
if(id){
if(flag == 1){
// node_element.style.display = "";
node_element.innerHTML = "Menu Item1" ;
flag=0;
}
}
}
function run_app(){
alert("run application...");
}
</script>
<body>
<table border="1px">
<tr>
<th id="id_item1" onmouseover="ChangeView('id_item1');" onmouseout="Recover('id_item1');" onclick="run_app();">Menu Item1</th>
</tr>
<tr>
<th>Menu Item2</th>
</tr>
</table>
</body>
</html>
/------------------------------
想实现,当鼠标放到Menu Item1时将它的背景改为绿色,但是却发现,那个绿色背景闪烁个不停,不知何故?请大家帮看看:)谢谢了。
...全文
471 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsdyy 2006-05-28
  • 打赏
  • 举报
回复
@ptma(守望者)
菜菜的问一句
为什么要加 if(id)呢?不加不可以么?
WiseNeuro 2006-05-28
  • 打赏
  • 举报
回复
谢谢大家.效果实现了.
tsdyy():加if(id)是为了防止id为空.
ptma 2006-05-26
  • 打赏
  • 举报
回复
你无非就是想在鼠标移入移出时改背景色吗,那用那么麻烦
<html>
<head><title>Design Menu</title></head>
<script language="javascript" type="text/javascript">
var flag = 0;
function ChangeView(id){
if(id)
id.style.backgroundColor="#80ff00";
}
function Recover(id){
if(id)
id.style.backgroundColor="";
}
function run_app(){
alert("run application...");
}
</script>
<body>
<table border="1px">
<tr>
<th id="id_item1" onmouseover="ChangeView(this);" onmouseout="Recover(this);" onclick="run_app();">Menu Item1</th>
</tr>
<tr>
<th>Menu Item2</th>
</tr>
</table>
</body>
</html>

什么都不能 2006-05-26
  • 打赏
  • 举报
回复
<html>
<head><title>Design Menu</title></head>
<script language="javascript" type="text/javascript">
var flag = 0;
function ChangeView(id){
var node_element = document.getElementById(id);
if(id){
if(flag == 0){
node_element.bgColor="#80ff00";
//node_element.innerHTML = "<font style='background-color: #80ff00'>Menu Item1</font>" ;
flag = 1;
}
}
}
function Recover(id){
var node_element = document.getElementById(id);
if(id){
if(flag == 1){
// node_element.style.display = "";
node_element.bgColor="";
//node_element.innerHTML = "Menu Item1" ;
flag=0;
}
}
}
function run_app(){
alert("run application...");
}
</script>
<body>
<table border="1px">
<tr>
<th id="id_item1" onmouseover="ChangeView('id_item1');" onmouseout="Recover('id_item1');" onclick="run_app();">Menu Item1</th>
</tr>
<tr>
<th>Menu Item2</th>
</tr>
</table>
</body>
</html>
wasuka 2006-05-26
  • 打赏
  • 举报
回复
木用过FF
WiseNeuro 2006-05-26
  • 打赏
  • 举报
回复
我是在firefox1.5.0.3下测试的.楼上的可以满足我的要求.闪烁是不是因为使用th标签的innerHTML引起的?
wasuka 2006-05-26
  • 打赏
  • 举报
回复
<body>
<table border="1px">
<tr>
<th id="id_item1" onmouseover="this.bgColor='green'" onmouseout="this.bgColor=''">Menu Item1</th>
</tr>
<tr>
<th>Menu Item2</th>
</tr>
</table>
</body>
wasuka 2006-05-26
  • 打赏
  • 举报
回复
我这儿效果跟你不一样。绿色一闪而过,然后就白了

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧