字符串我使用這個功能,可以幫助我的webdevelopers找到網頁中的一段代碼:JavaScript不能找到包含方括號
function findString (str) {
var strFound;
strFound=self.find(str);
if (strFound && self.getSelection && !self.getSelection().anchorNode){
strFound=self.find(str);
}
if (!strFound) {
strFound=self.find(str,1,1)
while (self.find(str,1,1)) continue
}
}
的問題是,當我輸入以下字符串例如:
array[1]
它找不到它!這是奇怪的,因爲我試過這個功能,它可以找到任何其他字符串。 那麼,如何使用此函數來查找包含方括號的字符串(如果可能,不使用正則表達式)?
謝謝
問候
我編輯了帖子。我忘記了左括號,但即使如此,它不起作用。你能「pastebin」你的代碼嗎?謝謝。 – Zakaria 2010-08-30 13:32:58
函數findString(str){var strFound; strFound = self.find(str);如果(strFound && self.getSelection &&!self.getSelection()。anchorNode){ strFound = self.find(str); } 如果{ strFound = self.find(STR,1,1) 而(self.find(STR,1,1))繼續 } 警報(strFound)(strFound!); } $(document).ready(function(){ findString(「array [1]」); }); – Zafer 2010-08-30 13:45:16