`嗨,伙计们。我创建一个程序,允许用户将数据输入到文本框中,然后将数据传递到不同的函数中,并返回结果以用于测试目的。如何在JavaScript函数中传递多个参数并打印结果?
他们大多数工作,但即时通讯数据与功能,采取2个或更多变量传递数据时遇到困难。
多参数功能只会打印1功能,然后停止。其余的工作正常。
这里有一个例子
代码:
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来说是新的。
谢谢!
变量名称不能以数字开头。 – 2012-08-14 21:52:45
'function testThree(1,2,3)'???空功能体?你想做什么? – 2012-08-14 21:53:44
如果你创建了jsfiddle,它会有所帮助。 – 2012-08-14 21:54:49