-1

`嘿伙计们。我正在创建一个程序,允许用户将数据输入文本框,然后将数据传递到不同的函数并返回结果以用于测试目的。

它们中的大多数都可以工作,但是我在使用包含 2 个或更多变量的函数传递数据时遇到了麻烦。

多参数函数只会打印第一个函数,然后停止。其余的工作正常。

这是一个例子

代码 :

function testOne(1)
{}

function testTwo(1,2)
{}

function testThree(1,2,3)
{}

function printTests()
{
document.writeln("testOne" + testOne(inputOne.value)) //Works fine
document.writeln("testTwo" + testTwo(inputOne.value, inputTwo.value)) //Stops here
document.writeLn("testThree" + testThree(inputOne.value, inputTwo.value, 
inputThree.value)) //doesnt work, it stops at whatever method has 2 variables, prints it and then stops.
}

我的输入看起来像这样。

<input type="text" id="inputOne">
<input type="text" id="inputTwo>
<input type="text" id="inputThree">

所以基本上我只希望我的文本值通过每个方法传递,并在单击按钮时显示返回。但是,如果该函数接受 2 个或更多变量,则它不起作用,因为它会正确打印该函数,但不会打印它后面的函数。

任何想法为什么?提前谢谢你,如果我犯了一个粗心的错误,我很抱歉,这是我的第一个问题,我是 Script 新手。

谢谢!

4

2 回答 2

0

重写你的函数,使参数不是数字。

function testOne(var_one)
{}

function testTwo(var_one,var_two)
{}

function testThree(var_one,var_two,var_three)
{}

这意味着您在函数内部使用的任何地方现在都1应该阅读var_one

于 2012-08-14T21:54:48.027 回答
0

变量名称不能以数字开头。

你的意思可能是这样的:

function testOne(input){ return input; }

function testTwo(first,second){ return "" + first + " " + second; }

function testThree(first,second,third){return "" + first + " " + second + " " + third; }
于 2012-08-14T21:54:56.920 回答