前段时间调试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. ios微信支付 v3

    V2版本和V3版本存在很大的差异. 1. 从成功通过微信支付商户的资料审核返回的邮件开始: 你可以获得这些参数  appid,appSecret,partnerID,    partnerKey(从平 ...

  2. .3-Vue源码之数据劫持(1)

    写了一半关机了,又得重新写,好气. 上一节讲到initData函数,其中包含格式化.代理.监听. // Line-3011 function initData(vm) { var data = vm. ...

  3. css3+div画大风车

    今天已经礼拜三了,周天小颖家的佩佩就要结婚啦,小颖要去当伴娘了,哈哈哈哈哈哈,想想都觉得乐开了花,不过之前她给我说让我当她伴娘时,我说我要减肥,不然她那么瘦弱,我站旁边就感觉像一个圆滚滚的小皮球,小颖 ...

  4. Python Web框架篇:Django文件上传

    上传方式: - Form表单上传文件 - Ajax上传文件 - 基于form表单和iframe自己实现ajax请求 1,创建项目 2,settings配置(注册app01,static路径等等这些)及 ...

  5. Python学习第一周

    一.我的第一个程序 print("Hello word!") 所以说python是一款非常简洁的语言,不像c,c++等等写一个简单的小程序还要调用一堆库.另外,python 3的版 ...

  6. css媒体查询:响应式网站

    css媒体查询:响应式网站 媒体查询 包含了一个媒体类型和至少一个使用如宽度.高度和颜色等媒体属性来限制样式表范围的表达式.CSS3加入的媒体查询使得无需修改内容便可以使样式应用于某些特定的设备范围. ...

  7. mybatis映射异常

    今天写项目突然遇到了这么个问题:  nested exception is org.apache.ibatis.reflection.ReflectionException: There is no  ...

  8. nohup和&后台运行,查看占用端口进程

    1.nohup 用途:不挂断地运行命令. 语法:nohup Command [ Arg - ] [ & ] 无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup ...

  9. php正则表达式,在抓取内容进行匹配的时候表现不稳定

    最近做了一个 抓取内容的程序,使用php的正则表达式对抓取的内容进行匹配,当进行大量匹配运算的时候,发现偶尔会出现匹配失败的情况.检查不出任何原因. 匹配失败导致匹配结果为空,最终导致写入数据库失败. ...

  10. JAVAWEB开发环境搭建,附JDK开发环境一键配置批处理bat

    JDK配置: CLASSPATH: .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar   JAVA_HOME: C:\Program Files\J ...