情况如下:
function vartest(a, b, c){
var angle =b;
var speed = a;
var g=c;
var time=0.5, v0, angle1;
v0 = speed;
alert("Type of angle 1"+typeof(angle1));
window.alert("angle "+angle);
angle1 = (angle*3.14)/180;
alert("Type of angle 1 second try: "+typeof(angle1));
window.alert("angle1 "+ angle1 );
}
//sliders from which i take angle, speed and gravity acceleration
$(function(){
$(".slider").slider()
$("#angle").slider({
value:30,
min:0,
max:250,
step:0.2,
slide: function (event, ui){
$( "#angres" ).html( ui.value );
angle = ui.value;
// trajgen();
}
});
$("#speed").slider({
value:0,
min:0,
max:250,
step:0.2,
slide: function (event, ui){
$("#spdres").html(ui.value);
speed = ui.value;
// trajgen();
}
});
$("#gravity").slider({
value:9.8,
min:0,
max:250,
step:0.2,
slide: function(event, ui){
$("#gravres").html(ui.value);
g = ui.value;
// trajgen();
}
});
});
//a fair attempt to assign the variable below with the initial values of
// the sliders, debugger shows that this doesn't work, it's OK but does not
// assign anything
$("#angres").html($('#angle').slider('value'));
var angle = $( "#angle" ).slider( "option", "value" );
$("#spdres").html( $("#speed").slider('value'));
var speed = $( "#speed" ).slider( "option", "value" );
$("#gravres").html($("#gravity").slider('value'));
var g = $( "#gravity" ).slider( "option", "value" );
if(speed!=undefined&&angle!=undefined&&g!=undefined){
vartest(angle, speed, g);
}
问题是 - 调整滑块后,他们成功地将angle
,speed
和gravity
传递给vartest
,但后来成为angle1 = (angle*3.14)/180
它允许angle1
='不可用'。如何解决这个问题。我第4天就是在解决这个问题,由于我在这里的一个人的努力和帮助,我能够将angle1
从NaN
更改为“不可用”#39;我应该承认,即使现在初始化angle1
是NaN
,但与之前的尝试不同,此angle1
从NaN
更改为“不可用”#39;这是一个公平的进步。但是,angle1
的类型无论在angle1= (angle*3.14)/180;
行之前还是之后都是数字。如果没有滑块功能,我设置了一个值,让我们说angle =150
然后angle1
就可以了。