问题
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