Num*_*er8 4 javascript jsfiddle
我有一些html/javascript在我的.cshtml文件中有效.
当我尝试将其移动到jsfiddle进行实验时,它不起作用.
不知道如果这是我缺乏javascript经验,jsfiddle经验,可能两者....
HTML:
<div>
<button name="startBtn" id="startBtn" onclick="startTimer">Start</button>
</div>
Run Code Online (Sandbox Code Playgroud)
(我也尝试了"startTimer()"作为onclick属性;结果相同.)
JavaScript的:
function startTimer() { alert("startTimer"); }
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时,我在控制台中看到了这个:
未捕获的ReferenceError:未定义startTimer
我在俯瞰什么?
(jsfiddle:http://bit.ly/1buQx9t )
abc*_*123 11
首先,您必须将框架设置为No wrap - in <head>,而不是onLoad.

描述
onLoad与window.onload=function(){[YOU ARE TYPING HERE]}JavaScript或$(function(){[YOU ARE TYPING HERE]});jQuery中的相同.
No wrap - in <head> 是相同的 <head><script type="text/javascript">[YOU ARE TYPING HERE]</script</head>
No wrap - in <body> 是相同的 <body>[HTML CODE HERE]<script type="text/javascript">[YOU ARE TYPING HERE]</script></head>
我希望这会清除jsFiddle中的设置,它们可能会有些混乱.
其次你HTML的错误:
HTML
<div>
<input type="button' value='"Start" onclick="startTimer()"/>
</div>
Run Code Online (Sandbox Code Playgroud)
描述
onclick="startTimer"被改为onclick="startTimer()"这将执行该功能.
你那里有一些奇怪的引号(在你的小提琴中),而且你忘记了()函数名称后面的内容。使用:
<input type="button" value=" Start " onclick="startTimer()" />
Run Code Online (Sandbox Code Playgroud)