`嗨,夥計們。我創建一個程序,允許用戶將數據輸入到文本框中,然後將數據傳遞到不同的函數中,並返回結果以用於測試目的。如何在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