+ -
当前位置:首页 → 问答吧 → 菜鸟又提问了.

菜鸟又提问了.

时间:2010-05-18

来源:互联网

return false;这个语句是不是只有onclick才有效啊./
我把连接改了onmouseover 这个是鼠标移动上去发现的行为.
但是我点击了它会跳转到新的窗口里.

作者: rao3324180   发布时间: 2010-05-18

return false;
就是返回一个否,如果在函数里,则下面的程序不再执行.

作者: 8yong8   发布时间: 2010-05-18

引用:
原帖由 8yong8 于 2010-5-18 16:41 发表
return false;
就是返回一个否,如果在函数里,则下面的程序不再执行.
你还不明白我的意思啊.
                     <li><a href="images/Lin_Zhi_Ling.jpg" title="我是林志玲!" onmouseover="showPic(this); return false;">林志玲</a></li>
我想让图片在本窗口显示.但设置了onmouseover以后就无效了.在onclick中才有效啊.不知道是不是onclick才有效的

作者: rao3324180   发布时间: 2010-05-18

能贴点代码看看不,能跑的那种?

作者: zhu104210362   发布时间: 2010-05-18

return false 是会组织浏览器默认行为

比如你给
锚点a监听他的click事件 return false 这个锚点就不会发生跳转
表单form监听submit事件  return false 这个表单就不能提交

浏览器好像没有mouseover事件是发生某项默认事件吧 当然不会发生任何事

作者: phoenix2212   发布时间: 2010-05-18


<!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" lang="zh-CN"> <head> <style type="text/css"> img{border:1px solid #ccc;} #placeholder{margin:0 auto;width:95px;height:115px;display:block;} </style> </head> <body> <h1>what to buy</h1> <ul> <li><a href="images/Cai_Yi_Lin.jpg" title="我是蔡依林!" onmousedown="showPic(this); return false;">蔡依林</a></li> <li><a href="images/Lin_Xin_Ru.jpg" title="我是林心如!" onclick="showPic(this); return false;">林心如</a></li> <li><a href="images/Lin_Yi_Chen.jpg" title="我是林依晨!" onmouseout="showPic(this); return false;">林依晨</a></li> <li><a href="images/Lin_Zhi_Ling.jpg" title="我是林志玲!" onmouseover="showPic(this); return false;">林志玲</a></li> </ul> <img id="placeholder" src="images/demo.gif" width="95" height="115" alt="my image gallery" /> <script type="text/javascript"> function showPic(whichpic){ var blue = whichpic.getAttribute("href"); var element=document.getElementById("placeholder") element.setAttribute("src",blue) } </script> </body> </html>
 提示:您可以先修改部分代码再运行
大家看看.

作者: rao3324180   发布时间: 2010-05-18


<!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" lang="zh-CN"> <head> <style type="text/css"> img{border:1px solid #ccc;} #placeholder{margin:0 auto;width:95px;height:115px;display:block;} </style> </head> <body> <h1>what to buy</h1> <ul> <li><a href="http://www.google.com.hk/images/srpr/nav_logo13.png" title="我是蔡依林!" onmouseover="showPic(this);" onclick="return false">onmouseover</a></li> <li><a href="http://bbs.blueidea.com/images/default/logo.gif" title="我是林心如!" onclick="showPic(this);return false">onclick</a></li> <li><a href="http://www.google.com/intl/zh-CN/images/logos/translate_logo.gif" title="我是林依晨!" onmousedown="showPic(this);" onclick="return false">onmousedown</a></li> </ul> <img id="placeholder" src="images/demo.gif" width="95" height="115" alt="my image gallery" /> <script type="text/javascript"> function showPic(whichpic){ var blue = whichpic.getAttribute("href"); var element=document.getElementById("placeholder") element.setAttribute("src",blue) } </script> </body> </html>
 提示:您可以先修改部分代码再运行
这样吗?

作者: zhu104210362   发布时间: 2010-05-19

引用:
原帖由 zhu104210362 于 2010-5-19 13:36 发表
[html]


       
              
                     img{border:1px solid #ccc;}
                     #placeholder{margin:0 auto;width:95px;height:115px;display:block;}
              
       
       
              what to buy
              
                     onmouseover
                     onclick
                     onmousedown
              
        ...
对,这就是我想要的效果了.
onmouseover的a标签里为什么还要加onclick="return false;" 才可以点击连接的时候在本窗口打开.而不是在新窗口打开的

作者: rao3324180   发布时间: 2010-05-21