<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<a id="a1" οnclick="s()" href="javascript:add(12)">点我</a>
<a id="a2" οnclick="theVar=this.href; alert(theVar); alert(typeof(theVar));return false;" href="http://zhidao.baidu.com/question/14453552.html">来吧</a>
</body>
<script>
function s(){
var theVar=document.getElementsByTagName("a")[0].href;
alert(theVar);
alert(typeof(theVar));
return false;
}
function add(id){
alert("add方法的id:"+id);
}
</script>
</html>
感受一下js代码直接写在a标签里和写在<script>标签fucntion里的区别:
a标签里的return false是为了不跳到链接对应的网页,但是return false写在<script>里不管用还是会跳到对应的网页