Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)
来源:互联网 发布:python获取不了源代码 编辑:程序博客网 时间:2024/06/05 02:57
前段时间调试html报了这样的一个错误
Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)
我的html 代码为
<a href="javascript:void(0)" onclick="download()">下载pdf</a>
解决方案为:
修改onclick 里面的名称,比如上面的download 改为 downloadpdf() ,意思就是不要用download作为方法名就好了
以下是思考过程
script 为
function download() {
console.log(‘xxxxx')
}
代码会报错
index.html:25 Uncaught TypeError: download is not a function
at HTMLAnchorElement.onclick (index.html:25)
探索发现,原因是a 标签的onclick事件会解析为
function(){
download()
}
而运行该代码的作用域就是 a标签本身
<a href="javascript:void(0)" class="down_btn downloadButton" onclick=“console.log(this);download()"></a>
运行后
而a标签有一个download 属性
http://www.w3school.com.cn/tags/att_a_download.asp
所以啊。这里运行的download就是 this.download 而这个是string 空字符串。我们现在却要运行为function就报错了
阅读全文
0 0
- Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)
- Uncaught TypeError: search is not a function at HTMLAnchorElement.onclick (airport.do:70)
- 关于Uncaught TypeError: type is not a function at HTMLAnchorElement.onclick (indexjsp:71)的解决
- Uncaught TypeError: XX is not a function at HTMLInputElement.onclick
- Uncaught TypeError: XX is not a function at HTMLInputElement.onclick
- Uncaught ReferenceError: resource is not defined at HTMLAnchorElement.onclick (learn_demo01.html
- Uncaught TypeError: undefined is not a function
- Uncaught TypeError: string is not a function
- Uncaught TypeError: object is not a function
- Uncaught TypeError: undefined is not a function
- Uncaught TypeError: undefined is not a function
- Uncaught TypeError: object is not a function
- Uncaught TypeError: boolean is not a function
- Uncaught TypeError: $(...).appendChild is not a function
- Uncaught TypeError: sum is not a function
- Uncaught TypeError: search is not a function
- Uncaught TypeError: $(...).Validform is not a function
- Uncaught TypeError: $(...).on is not a function
- C 标准库
- 唯快不破:高性能网络服务器--I/O复用 select poll epoll_wait之间的区别
- HDU 畅通工程(优美的数据结构——并查集)
- DNS
- Project trap
- Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)
- js 刷新页面
- 图像压缩——小波变换(Wavelet Transform)从连续小波变换谈到离散小波变换
- easyui 入门
- 八套卷第八套
- 实现跟随手指移动的小球—跟随移动颜色变化哦!
- 云星数据---Scala实战系列(精品版)】:Scala入门教程052-Scala实战源码-Scala implicit 操作03
- Eclipse开发最常用快捷键15
- js基础知识