• js获取get方式传递的参数


     String.prototype.GetValue= function(parm) {  
       var reg = new RegExp("(^|&)"+ parm +"=([^&]*)(&|$)");  
       var r = this.substr(this.indexOf("?")+1).match(reg);  
       if (r!=null) return unescape(r[2]); return null;  
     }
    完整测试代码
    test.html
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    
    
    <script>
    	String.prototype.getValue= function(parm) {  
    		var reg = new RegExp("(^|&)"+ parm +"=([^&]*)(&|$)");  
    		var r = this.substr(this.indexOf("?")+1).match(reg);  
    		if (r!=null) return unescape(r[2]); return null;  
    	} 
    	
    	function init(){
    		var url = window.location.href;
    		if(url.getValue('key1') == null){
    			alert('没有传递参数');
    		}else{
    			alert('传递参数:key1=' + url.getValue('key1'));
    			alert('传递参数:key2=' + url.getValue('key2'));
    		}
    	}
    </script>
    </head>
    <body onload="init();">
    <input type="button" onclick="window.location=window.location + '?key1=value1&key2=value2';return false;" value="传递参数"/>
    </body>
    </html>
  • 相关阅读:
    this指针详解
    C++处理异常
    C++中的this指针
    c++中的string类
    c面试题总结
    c++中的引用详解
    c++中的new和delete
    函数重载
    BST(二叉排序树)的插入与删除
    ccf行车路线
  • 原文地址:https://www.cnblogs.com/yueyue-love/p/6104762.html
Copyright © 2020-2023  润新知