[英]Javascript function undefined when called from input image onclick event
This seems really simple but I can't get it working... 这似乎很简单,但我无法正常工作...
function myfunction(id)
{
alert("ID: " + id);
}
There is a fiddle here http://jsfiddle.net/66ALW/ 这里有一个小提琴http://jsfiddle.net/66ALW/
The error I get in Firebug is ReferenceError: myfunction is not defined http://fiddle.jshell.net/_display/ (1) Line 1 我在Firebug中遇到的错误是ReferenceError:未定义myfunction http://fiddle.jshell.net/_display/(1 )第1行
You need set "No wrap in head" in jsfiddle to solve your problem: http://jsfiddle.net/66ALW/2/ 您需要在jsfiddle中设置“头部不缠绕”来解决您的问题: http : //jsfiddle.net/66ALW/2/
function myfunction()
{
alert("Reached");
}
code is ok. 代码还可以。
You are defining myfunction
in the onLoad
event, so it isn't being populated in the global namespace. 您是在
onLoad
事件中定义myfunction
的,因此不会在全局名称空间中填充它。 Thus, function appears to not exist. 因此,功能似乎不存在。 There are two solutions.
有两种解决方案。
window.myfunction = myfunction;
window.myfunction = myfunction;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.