JS Handling Skills for Jumping Values in Static Page html
- 2021-06-29 10:12:02
- OfStack
This article provides an example of JS processing techniques for jumping values in static page html.Share it for your reference, as follows:
In html by'?'Pass-by value:
<a href="index2.html?name=caoy"> Static value transfer </a>
Receive in page index2.html that jumps 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 transfer </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 request.getParameter()
parm : function(o) { // o: Parameter name or order
try {
return (typeof(o) == 'number' ? data[o][0] : data[index[o]][0]);
} catch (e) {
}
},
// Get Parameter Group , Similar request.getParameterValues()
parmValues : function(o) { // o: Parameter name or order
try {
return (typeof(o) == 'number' ? data[o] : data[index[o]]);
} catch (e) {}
},
// Does it contain parmName parameter
hasParm : function(parmName) {
return typeof(parmName) == 'string' ? typeof(index[parmName]) != 'undefined' : false;
},
// Get parameters Map , Similar request.getParameterMap()
parmMap : function() {
var map = {};
try {
for (var p in index) { map[p] = data[index[p]]; }
} catch (e) {}
return map;
}
}
}();
This allows you to jump values through html
More readers interested in JavaScript-related content can view this site's topics: Summary of JavaScript Switching Effects and Techniques, Summary of JavaScript Finding Algorithmic Techniques, Summary of JavaScript Animation Effects and Techniques, Summary of JavaScript Errors and Debugging Techniques, Summary of JavaScript Data Structure and Algorithmic Techniques.Summary of JavaScript Traversal Algorithms and Techniques and Summary of JavaScript Mathematical Operation Usage
I hope that the description in this paper will be helpful to everyone's JavaScript program design.