我发现onclick函数必须返回false才能继续使用href值,返回true则会阻止相同操作。我在这里也是这样使用的。如果返回false,则执行正确,继续使用URL,但是如果返回true,则也会打开URL页面。
那么从onclick函数返回true/false值之间有什么区别呢?
我正在使用Firefox 9.0.1和IE 7。以下是我的html文件。
<html>
<head>
<script language="JavaScript" type="text/javascript">
function clickthis()
{
alert("its onclick Function call ");
return true;
}
</script>
</head>
<body >
<a id="foo" onclick="clickthis();" href="http://google.com">google</a>
</body>
</html>
我对这种行为感到困惑。
onclick="return clickthis();"
, 但是@Lolo有正确的解决方案。 - JamesHalsall