This article describes the JS processing techniques for jumping and passing values in static page html. Share it for your reference, as follows:
Pass the value through "?" in html:
<a href="index2.html?name=caoy">Static value transmission</a>
Receive in the page index2.html that you jump to:
var name=UrlParm.parm("name");The code is as follows:
index.html:
<script type="text/javascript" src="getUrlParam.js"></script><a href="index2.html?name=caoy">Static value transmission</a>
index2.html:
<script type="text/javascript"> var name=UrlParm.parm("name"); alert(name);</script>getUrlParam.js:
UrlParm = function() { // url parameter 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 { // Get parameters, similar to request.getParameter() parm : function(o) { // o: parameter name or parameter order try { return (typeof(o) == 'number' ? data[o][0] : data[index[o]][0]); } catch (e) { } }, // Get parameter group, similar to request.getParameterValues() parmValues : function(o) { // o: parameter name or parameter order try { return (typeof(o) == 'number' ? data[o] : data[index[o]]); } catch (e) {} }, //Does the parmName parameter contain Parm : function(parmName) { return typeof(parmName) == 'string' ? typeof(index[parmName]) != 'undefined' : false; }, // Get the parameter Map, similar to request.getParameterMap() parmMap : function() { var map = {}; try { for (var p in index) { map[p] = data[index[p]]; } } catch (e) {} return map; } }}();This way you can transfer values through html
For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.