今天写了段简单的代码,点击<a>标签时却抛出了这个错误:Uncaught TypeError: download is not a function。代码以下:html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test</title>
<script>
function download() {
console.log(1);
}
</script>
</head>
<body>
<a onclick="download()">下载</a>
</body>
</html>
复制代码
<script>内明明已经定义了download函数,为何还会报download is not a function的错误呢?前端
因而,按下面的步骤尝试排查问题:bash
<a onclick="window.download()">下载</a>
复制代码
欢迎关注个人公众号:老干部的大前端,领取21本大前端精选书籍!函数