return false页面一样跳转

来源:百度知道 编辑:UC知道 时间:2024/04/29 15:22:02
一个图片浏览模块·
JavaScript代码如下:
function showpic(whichpic)
{
if(document.getElementById)
{
document.getElementById('placeholder').src=whichpic.href;
if(witchpic.title){
document.getElementById('desc').childNodes[0].nodeValue=whichpic.title;
}
else{
document.getElementById('desc').childNodes[0].nodeValue=whichpic.childNodes[0].nodeValue;
}
return false;
}
else
{return true;}
}
保存为album.js

Html代码如下:
<html>
<head>
<title>JoJo制作图片浏览器</title>
<link href="album.css" rel="stylesheet" type="text/css" />
<script src="album.js" type="text/javascript"></script>
</head>
<body>
<h1 style="font-size: %75; text-align: center;padding :1em; background-color:green;">JOJO图片浏览器</h1>
<div id="album&quo

<a onclick="return showpic(this);" href="2.jpg" title="加藤老伯"/>
这里你给A设置了href属性,对于A,只有HREF属性不是href="#",那么A就会跳转,所以除非你写成href="#",不然定会跳转

仍有问题:627574754,致力于JavaScript