Home >Web Front-end >JS Tutorial >How to parse js to get the parameter value in the current url and copy it to input_Basic knowledge

How to parse js to get the parameter value in the current url and copy it to input_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:31:491863browse
复制代码 代码如下:

  function getObject(objectId) {
    if (document.getElementById && document.getElementById(objectId)) {
        return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
        return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
        return document.layers[objectId];
    } else {
        return false;
    }
}
  function get(p){
//var url=location.search;
var url= document.URL.toString();
var tmpStr=p "=";
var tmp_reg=eval("/[?&]" tmpStr "/i");
if(url.search(tmp_reg)==-1)return null;
else{
    var a=url.split(/[?&]/);
    for(var i=0;i         if(a[i].search(eval("/^" tmpStr "/i"))!=-1)return a[i].substring(tmpStr.length);
}
}
 window.onload=function (){

getObject("key").value = get("k");  
//key作为input里的name名,接收到的值就是浏览器里的k参数
//k是浏览器里的参数名
 }

以上代码放在html页面最下方即可
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn