javascript函数未定义错误。句法? [英] javascript function not defined error. Syntax?
本文介绍了javascript函数未定义错误。句法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是小提琴 - > http://jsfiddle.net/y7MTs/5/
HTML:
< span>一:< / span>
< input type ='text'id ='ax'value ='4'size ='6'/>
< br />
< span>二:< / span>
< input type ='text'id ='bx'value ='2.5'size ='6'/>
< br />< br />
< button onclick ='mytest(ax.value,bx.value);'>立即开始< / button>
Javascript:
function mytest(a,b){
var x = [0,1,2,3,4,5];
var y = [100,120,140,160,180,200];
var myval = parseFloat(a) - x [3];
alert(myval);
解决方案在你的小提琴,该函数是在 onload
事件处理程序给出的回调的范围内。
在菜单在左上角,选择 no wrap -in< head>
。
固定小提琴: http://jsfiddle.net/dystroy/FrVE6/
This is driving me crazy. I cannot figure out why I get "mytest is not defined" error:
here's the fiddle --> http://jsfiddle.net/y7MTs/5/
HTML:
<span>One: </span>
<input type='text' id='ax' value='4' size='6'/>
<br/>
<span>Two: </span>
<input type='text' id='bx' value='2.5' size='6'/>
<br/><br/>
<button onclick='mytest(ax.value, bx.value);'>Go Now</button>
Javascript:
function mytest(a, b) {
var x = [0, 1, 2, 3, 4, 5];
var y = [100, 120, 140, 160, 180, 200];
var myval = parseFloat(a) - x[3];
alert(myval);
}
解决方案 In your fiddle, the function is in the scope of a callback which is given to the onload
event handler.
In the menu at top left, choose no wrap - in <head>
.
Fixed fiddle : http://jsfiddle.net/dystroy/FrVE6/
这篇关于javascript函数未定义错误。句法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文