判断字符串是否以XX开头
1.切割转换 var str = "ababaa",tags = jquery.trim(str);
2. indexOf方法运行 !tags.indexOf("aba") == true, 说明 tags以“abc” 开头,否则不是以“abc”开头。
3. 说明 indexOf()方法返回-1,0,>0的正数,而javascript number对象 等于0时能转换成false,其他值都只能转换成true;
The indexOf() method returns the position of the first occurrence of a specified value in a string.
If the Boolean object has no initial value, or if the passed value is one of the following:
0, -0, null, "", false, undefined, NaN
the object it is set to false. For any other value it is set to true (even with the string "false")!
This method returns -1 if the value to search for never occurs.
原文:http://www.cnblogs.com/rocky-fang/p/5167532.html