今天寫了段簡單的代碼,點擊<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本大前端精選書籍!函數