前段时间调试html报了这样的一个错误
Uncaught TypeError: download is not a function     at HTMLAnchorElement.onclick (index.html:25)
 
 
我的html 代码为
<a href="javascript:void(0)" class="down_btn downloadButton" onclick="download()"></a>
 
解决方案为:
修改onclick 里面的名称,比如上面的download 改为 download22222() 就好了
 
以下是思考过程 
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 属性

所以啊。这里运行的download就是 this.download 而这个是string 空字符串。我们现在却要运行为function就报错了
 
 
之前google查了一个类似的错误提示。
html如下
Total Storage: <input type="text" name="totalstorage">   
Total Bandwidth: <input type="text" name="totalbandwidth">   
<input type="button" value="totalbandwidthresult" onclick="debugger;totalbandwidth();">  
也是相同的错误
在debugger里面输入this是当前对象。
而输入totalbandwidth确实
<input type="text" name="totalbandwidth”>   
 
猜想this的上一级作用域就是document.forms[0]. 

Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)的更多相关文章

  1. Uncaught TypeError: upload is not a function at HTMLInputElement.onclick

    js 中标签的id名称不能和方法名一样, <tr> <td><input type="button" id="login" val ...

  2. 360浏览器Uncaught TypeError: object is not a function问题

    刚刚360浏览器提示 Uncaught TypeError: object is not a function,找了半天发现问题是我有一个按钮,id和方法重复了,所以提示这个. <input t ...

  3. “Uncaught TypeError: string is not a function”

    http://www.cnblogs.com/haitao-fan/archive/2013/11/08/3414678.html 今天在js中写了一个方法叫做search(),然后点击按钮的时候提示 ...

  4. Uncaught TypeError: $(...).daterangepicker is not a function

    本文为博主原创,未经允许不得转载: 在用bootstrap做一个日期插件的时候,代码和js,css等都是拷贝网上下载下来的实例,但是在 调试的时候,浏览器控制台一直报错 Uncaught TypeEr ...

  5. chrome浏览器Uncaught TypeError: object is not a function问题解决

    今天测试多浏览器的时候,chrome浏览器出现Uncaught TypeError: object is not a function: 解决办法:(不知道为啥子)改一下js的方法名字就可以了

  6. Uncaught TypeError: undefined is not a function

    index.html <script src="resources/sap-ui-core.js" id="sap-ui-bootstrap" data- ...

  7. js Uncaught TypeError: undefined is not a function

    如下代码: var columns={}; var column={}: column.name='张三'; columns.push(column); 会出现Uncaught TypeError: ...

  8. Google Chrome Uncaught TypeError: object is not a function

    <html> <script type="text/javascript"> function testForm(){ alert("hello ...

  9. Uncaught TypeError: $(…).orgcharts is not a function

    调整js顺序没有解决,最后增加NoConflict解决,注意红色部分 function initorgcharts() { var $jq = jQuery.noConflict(true); org ...

随机推荐

  1. 探索equals()和hashCode()方法

    探索equals()和hashCode()方法 在根类Object中,实现了equals()和hashCode()这两个方法,默认: equals()是对两个对象的地址值进行的比较(即比较引用是否相同 ...

  2. onclick事件触发 input type=“file” 上传文件

    添加按钮: <input type="button" name="button" value="浏览" onclick="j ...

  3. Azure环境中Nginx高可用性和部署架构设计

    前几篇文章介绍了Nginx的应用.动态路由.配置.在实际生产环境部署时,我们需要同时考虑Nginx的高可用性和部署架构. Nginx自身不支持集群以保证自身的高可用性,商业版本的Nginx+推荐: T ...

  4. .8-Vue源码之AST(4)

    上一节讲完了超长的start函数,也同时完结了handleStartTag函数,接着continue进入下一轮while循环. 此时剩余的字符串状态如图:,切掉了<div id='app'> ...

  5. (转)linux下如何批量杀JAVA进程或某个进程方法

    在工作中经常需要停止JAVA进程,停止时间也比较长,那么有时候因为一些情况,需要把 linux 下JAVA所有进程 kill 掉,又不能用killall 直接杀掉某一进程名称包含的所有运行中进程(我们 ...

  6. poj 1254 Hansel and Grethel

    Hansel and Grethel Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2199   Accepted: 100 ...

  7. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I Lottery

    LotteryCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     64bit ...

  8. 一次线上Mysql数据库崩溃事故的记录

    文章简介 工作这几年,技术栈在不断更新,项目管理心得也增加了不少,写代码的速度也在提升,感觉很欣慰,毕竟是在一直进步,但是过程中也有许许多多的曲折,也踩过了数不尽的坑坑洼洼,从一个连百度都不知道用的萌 ...

  9. pycharm安装激活

    我的版本是pycharm-professional-2016.3.3 总体的安装步骤基本没什么,就是一直下一步,下一步就行了. 重要的最后的注册,找了一堆版本,最后用的server,注册成功. 注册码 ...

  10. DataProtection Key的选择

    代码位于: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver.cs private IKey FindDefau ...