本页面JS如何获取上一个页面超链接传来的参数 jsurlfunction 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 查下location的属性,然后看下它的一些属性 http://localhost/index.html?type=country&id=12&page=10 <script type="text/javascript"> var url = window.location; function getUrlParam(url,name){ var pattern = new RegExp("[?&]" + name +"\=([^&]+)","g"); var matcher = pattern.exec(url); var items = null; if(matcher != null){ try{ items = decodeURIComponent(decodeURIComponent(matcher[1])); }catch(e){ try{ items = decodeURIComponent(matcher[1]); }catch(e){ items = matcher[1]; } } } return items; } alert(getUrlParam(url,'type')); // country alert(getUrlParam(url,'id')); // 12 alert(getUrlParam(url,'page')); // 10 </script>另外function名应该叫getUrlParam而不是getUtlParam吧。 上面我写的url返回的是上一个页面的URL,而我想得到的参数在上一个页面的本页面URL中,location的一些属性只能得到本页面的url! Quote: 引用 2 楼 fdipzone 的回复:你这个是获取本页面连接中的参数吧?我想获取从上一个页面超链接传过来的参数,怎么破?函数名那个没有关系吧! var url = "www.zhangyunling.com?aada=adaa&adad=adasd&sdfs=asdad#did", reg = /([^\=\?|\&]+)\=([^\=\&\#]+)/g; var aa = url.match(reg); console.log(aa); url.replace(reg,function($1,$2,$3){ console.log($2+"="+$3); });看你的意思,是不是想要使用正则表达式实现?试试这样可以得到你想要的结果不。 當前頁面url後面的參數就是上一頁的超鏈接跳過來的,有什麼問題?你不是要獲取上一頁傳過來的參數麼? jquery排序的问题,排序完后tr事件没了。。。 JavaScript的一个简单问题: 请教屏蔽IE关闭按钮的方法 显示层的小问题 怎样判断google map 是街景模式? 大家来帮忙看看我遇到的这个问题 ShowModelessDialog的问题? 动态添加行的新增和页面加载问题 thanks.如何动态改变text的maxlength属性 20分:用DHTML工具实现一个滚动广告的动态网页(每次变化的广告不一样)并说明其具体实现步骤 怎样判断一个input的type为checkbox的选中属性??用 jQuery 这样的正则如何写
<script type="text/javascript">
var url = window.location;
function getUrlParam(url,name){
var pattern = new RegExp("[?&]" + name +"\=([^&]+)","g");
var matcher = pattern.exec(url);
var items = null;
if(matcher != null){
try{
items = decodeURIComponent(decodeURIComponent(matcher[1]));
}catch(e){
try{
items = decodeURIComponent(matcher[1]);
}catch(e){
items = matcher[1];
}
}
}
return items;
} alert(getUrlParam(url,'type')); // country
alert(getUrlParam(url,'id')); // 12
alert(getUrlParam(url,'page')); // 10 </script>
另外function名应该叫getUrlParam而不是getUtlParam吧。
reg = /([^\=\?|\&]+)\=([^\=\&\#]+)/g;
var aa = url.match(reg);
console.log(aa);
url.replace(reg,function($1,$2,$3){
console.log($2+"="+$3);
});看你的意思,是不是想要使用正则表达式实现?
试试这样可以得到你想要的结果不。
當前頁面url後面的參數就是上一頁的超鏈接跳過來的,有什麼問題?
你不是要獲取上一頁傳過來的參數麼?