var className = this.id;
if (className == 'pet-sitting' || className == 'walking' || className == 'mobile-grooming')
{}上面的className可以有任何值,如“宠物保姆2”、“宠物保姆3”或“宠物保姆4”等等。
我的问题是,如果我能做到这一点的话,我只能在“宠物看管”的情况下,在className上面修剪一下,如果我能做到这一点的话。
发布于 2013-11-27 12:42:26
使用indexOf()方法返回指定值第一次出现在string.Hope中的位置。:)
如果要搜索的值从未发生,则此方法返回-1。
var className = this.id;
if(className.indexOf('pet-sitting') > -1) {
//Your code
}发布于 2013-11-27 12:40:05
尝试使用replace()和regex
this.id.replace(/pet-sitting.+/g, "pet-sitting");regex:.+的意思是一个或一个字符
https://stackoverflow.com/questions/20242733
复制相似问题