zoukankan      html  css  js  c++  java
  • Uncaught TypeError: download is not a function at HTMLAnchorElement.onclick (index.html:25)

    前段时间调试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 Band <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]. 
  • 相关阅读:
    模式识别 第一章 概论
    高等代数9 欧几里得空间
    离散数学6 初等数论
    高等代数6 线性空间
    高等代数5 二次型
    GMOJ 6870. 【2020.11.17提高组模拟】ckw的树 (tree)
    1
    Virtual Tree 学习笔记
    [2020.11.14提高组模拟] 鬼渊传说(village)
    企业购置新车,各项费用会计入账以及案例分析
  • 原文地址:https://www.cnblogs.com/yoable/p/6390429.html
Copyright © 2011-2022 走看看