直接上报错代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="javascript:void" onclick="test()">点我</a>
<script>
function test() {
alert("1");
}
</script>
</body>
</html>
点击后,报错:unexpected end of input
检查以后发现在a标签的href属性哪里写错了void应该加上参数0,修改如下:
这里写代码片<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="javascript:void(0)" onclick="test()">点我</a>
<script>
function test() {
alert("1");
}
</script>
</body>
</html>
点击不在报错;
本文参考了:http://jingyan.baidu.com/article/fea4511a04bf56f7bb9125b7.html