码迷,mamicode.com
首页 > 其他好文 > 详细

常用功能的封装

时间:2017-03-13 13:00:35      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:封装   efi   exp   正则   多个   gif   匹配   his   多个参数   

function h5App(){

  this.setItem = function(key,val){
    var str = JSON.stringify(val)
    localStorage.setItem(key,str);
  }
  this.getItem = function(key){
    if (key == ‘‘ || key == undefined) {
    key = "produstList";
  }
  this.clear = function(){
    localStorage.clear();
  }

  //多个参数

  this.get_url = function (key){
    // 获取参数
    var url = window.location.search;
    // 正则筛选地址栏
    var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
    // 匹配目标参数
    var result = url.substr(1).match(reg);
    //返回参数值
    return result ? decodeURIComponent(result[2]) : null;
  };

  //+------
}

//持续更新

常用功能的封装

标签:封装   efi   exp   正则   多个   gif   匹配   his   多个参数   

原文地址:http://www.cnblogs.com/zzxx/p/6541880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!