JS问题求助!!!!如下:这个哪里出了问题呢?
<scriptlanguage="javascript">varnum1,num2;functioninput(num1,num2){num1=prompt("Pleas...
<script language="javascript">
var num1,num2;
function input(num1,num2){
num1=prompt("Please Enter The First Number !","")
num2=prompt("Please Enter The Second Number !","")
}
function asd(x,y){
if((x==null)||(y==null))alert("I Never Think So !");
else{
answer=Number(x)+Number(y);
alert(answer)
}
}
</script>
<form>
<input type="button" value="Plus" onclick="input(),asd(num1,num2)" />
</form> 展开
var num1,num2;
function input(num1,num2){
num1=prompt("Please Enter The First Number !","")
num2=prompt("Please Enter The Second Number !","")
}
function asd(x,y){
if((x==null)||(y==null))alert("I Never Think So !");
else{
answer=Number(x)+Number(y);
alert(answer)
}
}
</script>
<form>
<input type="button" value="Plus" onclick="input(),asd(num1,num2)" />
</form> 展开
2个回答
展开全部
你的num1 num2的值并没有传给x,y,所以x,y的值为空,提示的是”I Never Think So !”一般用按钮来触发,最好就是用一个函数来解决问题,代码如下:
<script language="javascript">
var num1,num2;
function input(num1,num2){
num1=prompt("Please Enter The First Number !","")
num2=prompt("Please Enter The Second Number !","")
var x=num1;
var y=num2;
//此处去掉你的asd(num1,num2)函数,直接将值传递给x,y
if((x==null)||(y==null))
{
alert("I Never Think So !");
}
else
{
answer=Number(x)+Number(y);
alert(answer);
}
}
</script>
<form>
<input type="button" value="Plus" onclick="input();" /> //此处你在input()后面忘了加”;”
</form>
<script language="javascript">
var num1,num2;
function input(num1,num2){
num1=prompt("Please Enter The First Number !","")
num2=prompt("Please Enter The Second Number !","")
var x=num1;
var y=num2;
//此处去掉你的asd(num1,num2)函数,直接将值传递给x,y
if((x==null)||(y==null))
{
alert("I Never Think So !");
}
else
{
answer=Number(x)+Number(y);
alert(answer);
}
}
</script>
<form>
<input type="button" value="Plus" onclick="input();" /> //此处你在input()后面忘了加”;”
</form>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询