js获取当前页面的url中id

var str = location.href; //获取到整个地址

indexof() :在字符串中从前向后定位字符和字符串;所有的返回值都是指在字符串的绝对位置,如为空则为- 1

str.indexof(’id’)                //从前向后 定位 id 第一次出现的位置
str.indexof(’id’,1)              //从前向后 定位 id 第1次出现的位置
str.indexof(’id’,5,2)        //从第五位往后两位找id下标
lastindexof() //在字符串中从后向前定位字符和字符串;

substring() 用法

str.substring(5)      //截取从第五位以后的所有字符串,5是下标

str.substring(0,5)     //截取从第0位后五位所有字符串

 

posted on 2017-06-02 18:43  JasonTech0713  阅读(407)  评论(0)    收藏  举报

导航