有代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function clear()
{
console.log("Hello World");
}
</script>
</head>
<body>
<button onclick="clear()">
点我
</button>
</body>
</html>
用浏览器打开之后,点击点我按钮,发现控制台并没有输出Hello World。
检查了代码许多遍,没有任何问题,
真是怀疑js了,
后来将clear函数名改为clear1
瞬间成功了
原因如下:
clear为js内置函数,换成其他的即可