2013-05-16 55 views
2

做類似的變量:調用JavaScript中的函數,用它

speak('Hello. Today is " + month + "/" + day + "/" + year + ", " + hours + ":" + minutes + ". I have couple suggestions of what to do today...Wanna go to the movies? Play some games? Go out to eat? Need anything else?') 

當他們寫道,它的字面說" + month + "/" + day + "/" + year + ", " + hours + ":" + minutes + "

speak('')是另一個腳本定義的函數。有可能把變量放在裏面嗎?

+1

更改雙引號('「')爲單引號(''') –

+0

或者將單引號改爲雙引號,速度要快得多。 – Antony

回答

3

這是因爲單引號和雙引號之間交替。你想選擇一個並一致地使用它。兩種風格都允許(所有單打或所有雙打),都不是首選,所以這是你的選擇。

0

JavaScript允許'single quotes'"double quotes"表示字符串的開始和結束。但是,你不能混合和匹配它們。那就是'this will cause an error"

所以,您需要將程序文本更改爲:

speak('Hello. Today is ' + month + '/' + day + '/' + year + ', ' + hours + ':' + minutes + '. I have couple suggestions of what to do today...Wanna go to the movies? Play some games? Go out to eat? Need anything else?') 

或:

speak("Hello. Today is " + month + "/" + day + "/" + year + ", " + hours + ":" + minutes + ". I have couple suggestions of what to do today...Wanna go to the movies? Play some games? Go out to eat? Need anything else?")