var testValue = "This is the Cookbook's test string";
var subsValue = "Cookbook";
var iValue = testValue(subsValue); // returns value of 12, index of substring
alert(iValue);
我正在通過Shelley Powers編寫Javascript食譜。但是我嘗試了這段代碼,我無法獲得12.這沒什麼!而且我在O'Reilly的勘誤頁面找不到正確的部分。我可以使用括號來獲取Javascript中的子串位置嗎?
圓括號真的有用嗎?我知道String對象的indexOf方法必須工作。 Like:
var testValue = "This is the Cookbook's test string";
var subsValue = "Cookbook";
var iValue = testValue.indexOf(subsValue);
alert(iValue); // This time I got the alert 12.
顯然,這是一個打字錯誤。 – simplyharsh