I am calling the javascript function while from the HTML onClick event. I works fine when the page is loaded but when i click the button while the document is not ready it gives undefined function error in the console.
<a onclick="myfunc(params)" href="javascript:void(0)" >Click Me</a>
myfunc is defined in another js file.
答案 0 :(得分:0)
您需要在页面的head部分调用包含此函数的javascript文件。我们使用脚本标记加载javascript文件并进行渲染阻止,这意味着首先加载所需的内容,然后加载此Click Me,然后只要此链接可见,就可以单击此处。