js中如何判断一个字符串包含另外一个字符串?

js中判断一个字符串包含另外一个字符串的方式比较多?



比如indexOf()方法,注意O是大写。



var test="this is a test";



if(test.indexOf("test")!=-1){

//不等于-1表示该字符串包含子字符串。

}

Jquery 判断当前完整的url是否包含指定的字符串

if (window.location.reload) {

    if(window.location.href.indexOf("/db/med_story/edit/?medical_story_id")!=-1) {
        console.log(Show_Image_Url());
    }

}

 

posted on 2018-01-26 18:03  星河赵  阅读(568)  评论(0)    收藏  举报

导航