如何在JavaScript中的IF語句中將具有布爾值的變量用作條件?如何在JavaScript中的IF語句中將具有布爾值的變量用作條件?
patt1 = new RegExp ("time");
var searchResult = (patt1.test("what time is it")); // search for the word time in the string
// and return true or false
If (searchResult = true) // what is the right syntax for the condition?
{
document.write("Word is in the statement");
document.write("<br />");
}
如果(信息搜索結果) – 2012-01-09 19:42:36
你可以只使用變量作爲「條件」:'如果(信息搜索結果)',使用一個=不會起作用,因爲=運算符是分配在Java和JScript,如果你想使用這種語法,你應該使用'if(searchResult == true)' – jere 2012-01-09 19:43:09