Tuesday, June 26, 2012

[JavaScript] 簡單的字串搜尋


var str = "Hi Av8d";
var chk = str.search(/hi/i);
if(chk==-1){
alert("hi不在Hi Av8d字串中");
}else{
alert("hi有在Hi Av8d字串中");  //本案例會跳出這個視窗
}


備註:後面加參數i,代表不區分大小寫。

No comments:

Post a Comment