前段时间调试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. 自学ConcuurentHashMap源码

    自学ConcuurentHashMap源码 参考:https://my.oschina.net/hosee/blog/675884 http://www.cnblogs.com/ITtangtang/ ...

  2. 微信公众平台开发接口PHP SDK

    以前没接触过微信公众平台开发,前几天刚找到实习公司就要求我做一个微信公众平台的应用,于是乎开始学习微信公众平台开发接口的调用,看开发文档之后还是不知道从何入手,只好上网找入门资料,终于在方倍工作室找到 ...

  3. Fastify 系列教程三 (验证、序列化和生命周期)

    Fastify 系列教程: Fastify 系列教程一 (路由和日志) Fastify 系列教程二 (中间件.钩子函数和装饰器) Fastify 系列教程三 (验证.序列化和生命周期) 验证 Fast ...

  4. Go Global 之怎样在全球Azure上使用Azure Free Account

    随着中国用户出海的越来越多,同学们自学Azure Global 功能的积极性也越来越高.怎样开启Azure Global 账号,有哪些Global Azure的功能可以免费使用,能不能用国内的信用卡和 ...

  5. C Run-Time Error R6034问题的解决

    1.问题描述 这两天一直在用vs2008编写一个小项目,需要在c++代码中通过命令行的方式调用cl.exe和link.exe,也就是给编译器cl和链接器link传递参数,然后编译链接生成可执行文件ex ...

  6. OOA、OOD、OOP分别是什么?

    什么是面向对象分析(OOA)? "面向对象分析是一种分析方法,这种方法利用从问题域的词汇表中找到的类和对象来分析需求." 什么是面向对象设计(OOD)? "面向对象设计是 ...

  7. HTTP响应头信息(Response Headers)与请求头信息(Request Headers)

    打开了电影天堂网站,我们鼠标右键“检查”->打开“开发者工具”->选择“Network”. 刷新网页,选择某一文件点击(此处我是点击db.css),可以观察到Response Header ...

  8. 二:Maven中pom.xml元素详解

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6628201.html  一个pom.xml中包含了许多标签,各个标签是对项目生命周期.依赖管理的配置.常用的主 ...

  9. OpenTSDB-Querying or Reading Data

    Querying or Reading Data OpenTSDB offers a number of means to extract data such as CLI tools, an HTT ...

  10. github设置

    ssh-key: https://help.github.com/articles/generating-ssh-keys http://segmentfault.com/q/101000000013 ...