原文地址:http://blog.csdn.net/ywl570717586/article/details/53130863

今天处理html标签里的onclick功能的时候总是报错:Uncaught ReferenceError: dosave is not defined(…)

找了半天都没发现错在哪,最后发现原来是我写法不对,正确写法如下:

html:

[html] view plain copy
  1. <input type="button" value="立即登录" onclick="dosave();"/>  

js:

[javascript] view plain copy
  1. dosave = function (){  
  2.         alert("成功啦!");  
  3.     }  

错误写法一般有以下两种,很致命:

[javascript] view plain copy
  1. function dosave(){  
  2.         alert("会报错!!");  
  3.     }  

[javascript] view plain copy
  1. var dosave = function (){  
  2.         alert("会报错!!");  
  3.     }  

为什么会这样,因为:

html页面调用js文件里的函数,写法必须为dosave = function (){}形式,其他方式写,html页面会搜索不到该函数。

相关文章:

  • 2022-12-23
  • 2021-08-28
  • 2021-03-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案