截取网址参数

      getQueryString: function (name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
        var r = location.href.split('#')[1].substr(location.href.split('#')[1].indexOf('?') + 1).match(reg)  // 获取url中"?"符后的字符串并正则匹配
        var context = ''
        if (r !== null) {
          context = r[2]
        }
        reg = null
        r = null
        return context === null || context === '' || context === 'undefined' ? '' : context
      }

例如:http://192.168.10.100/#/DirectoryThumbnails?book_id=21&course_id=54

想截取book_id = getQueryString.('book_id')

posted @ 2017-09-26 15:24  小短腿奔跑吧  阅读(173)  评论(0编辑  收藏  举报