如题. 想根据单击事件的返回结果,来出来超链接是否失效.
本来想js直接返回false因该可以. 谁知不行.
<html>
<head>
<script type="text/javascript">
function checkOrderLock()
{
return false;
}
</script>
</head>
<body>
<a href="#" onclick="checkOrderLock();window.location.href='http://www.google.com'";>google</a>
</body>
</html>
<head>
<script type="text/javascript">
function checkOrderLock()
{
return false;
}
</script>
</head>
<body>
<a href="#" onclick="checkOrderLock();window.location.href='http://www.google.com'";>google</a>
</body>
</html>
后 google到 http://www.cnblogs.com/blodfox777/archive/2008/08/27/1277997.html
改成:
<html>
<head>
<script type="text/javascript">
function checkOrderLock()
{
return false;
}
</script>
</head>
<body>
<a href="#" onclick="if(!checkOrderLock()){return false;} window.location.href='http://www.google.com'";>google</a>
</body>
</html>
<head>
<script type="text/javascript">
function checkOrderLock()
{
return false;
}
</script>
</head>
<body>
<a href="#" onclick="if(!checkOrderLock()){return false;} window.location.href='http://www.google.com'";>google</a>
</body>
</html>
就可以了. 这个...
许久之后 是我自己2了,应该是 onclick="return checkOrderLock();"这里return 必不可少,不然不会判断当前是否继续执行。 想想和程序的return是一样的,好好学js:]