HTML按钮onclick调用javascript文件无法正常工作 [英] HTML button onclick calling javascript file not functioning
本文介绍了HTML按钮onclick调用javascript文件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在头部导入了javascript文件,如下所示:
I imported the javascript file in the head like this :
<script type="text/javascript" src="js/ISO_TR_230-9.js"></script>
该文件包含一个函数 calc1 ,其设置如下: / p>
That file contains a function calc1 which is set up like this :
function calc1() {}
我从一个设置如下的按钮调用 calc1 :
I am calling calc1 from a button that is set up like this :
<button type="button" onclick="calc1()">Calculate</button>
单击按钮后,我收到错误 calc1未定义。发生这种情况有什么事吗?
Upon clicking the button I receive the error calc1 is not defined. Is there anything that could be happening where this occurs?
推荐答案
<button type="button" onclick="calc1()">Calculate</button>
这种设置事件的方式很旧。我想你打电话的时候已经创造了。
That style of setting the events is old. I think hast been created when you call it.
所以尝试将处理程序放在JS文件中。和,来自Jq的window.onload()或Smthn。
so try put the handler in the JS-file. and, window.onload() or Smthn from Jq.
这篇关于HTML按钮onclick调用javascript文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文