先上代码:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<div>
<a href="www.baidu.com" onclick="return checkForm()">点击我</a>
</div>
</body>
</html>
<script type="text/javascript">
function checkForm()
{
return true;
}
</script>
测试结果:测试发现,onclick里加return时,checkForm()方法必须返回true才可以触发a标签的跳转。而不加return的时候,无论checkForm()返回false还是true,都会触发a标签的跳转。