HTML button onclick calling javascript file not functioning [closed]

我怕爱的太早我们不能终老 提交于 2020-01-07 02:38:11

问题


I imported the javascript file in the head like this :

<script type="text/javascript" src="js/ISO_TR_230-9.js"></script>

That file contains a function calc1 which is set up like this :

function calc1() {}

I am calling calc1 from a button that is set up like this :

<button type="button" onclick="calc1()">Calculate</button>

Upon clicking the button I receive the error calc1 is not defined. Is there anything that could be happening where this occurs?


回答1:


<button type="button" onclick="calc1()">Calculate</button>

That style of setting the events is old. I think hast been created when you call it.

so try put the handler in the JS-file. and, window.onload() or Smthn from Jq.



来源:https://stackoverflow.com/questions/11767295/html-button-onclick-calling-javascript-file-not-functioning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!