在靜態頁面html中跳轉傳值

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   sp   java   for   div   

在html中通過"?"傳值--------<a href="index2.html?name=caoy">靜態傳值</a>

在跳轉到的頁面index2.html中接收----var name=UrlParm.parm("name");

代碼如下:

 

index.html:

<script type="text/javascript"&nbsp; src="js/getUrlParam.js"></script><a href="index2.html?name=caoy">靜態傳值</a>

index2.html:

<script type="text/javascript">    var name=UrlParm.parm("name");    alert(name);</script>

getUrlParam.js:

UrlParm = function() { // url參數    var data, index;    (function init() {      data = [];      index = {};      var u = window.location.search.substr(1);      if (u != ‘‘) {        var parms = decodeURIComponent(u).split(‘&‘);        for (var i = 0, len = parms.length; i < len; i++) {          if (parms[i] != ‘‘) {            var p = parms[i].split("=");            if (p.length == 1 || (p.length == 2 && p[1] == ‘‘)) {// p | p=              data.push([‘‘]);              index[p[0]] = data.length - 1;            } else if (typeof(p[0]) == ‘undefined‘ || p[0] == ‘‘) { // =c | =              data[0] = [p[1]];            } else if (typeof(index[p[0]]) == ‘undefined‘) { // c=aaa              data.push([p[1]]);              index[p[0]] = data.length - 1;            } else {// c=aaa              data[index[p[0]]].push(p[1]);            }          }        }      }    })();    return {      // 獲得參數,類似request.getParameter()      parm : function(o) { // o: 參數名或者參數次序        try {          return (typeof(o) == ‘number‘ ? data[o][0] : data[index[o]][0]);        } catch (e) {        }      },      //獲得參數組, 類似request.getParameterValues()      parmValues : function(o) { //  o: 參數名或者參數次序        try {          return (typeof(o) == ‘number‘ ? data[o] : data[index[o]]);        } catch (e) {}      },      //是否含有parmName參數      hasParm : function(parmName) {        return typeof(parmName) == ‘string‘ ? typeof(index[parmName]) != ‘undefined‘ : false;      },      // 獲得參數Map ,類似request.getParameterMap()      parmMap : function() {        var map = {};        try {          for (var p in index) {  map[p] = data[index[p]];  }        } catch (e) {}        return map;      }    }  }();  

 

在靜態頁面html中跳轉傳值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.