`
jickcai
  • 浏览: 247505 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

getQueryParamValue 得到URL中的参数类似 request.getParamater("videoid")

阅读更多
<html>
<head>
<title>得到URL中的参数摘自 swfObject.js</title>
</head>
<body>
<div id="div1">This is my first layer</div>
<script>
function urlEncodeIfNecessary(s) {
var regex = /[\\\"<>\.;]/;
var hasBadChars = regex.exec(s) != null;
return hasBadChars && typeof encodeURIComponent != UNDEF ? encodeURIComponent(s) : s;
}

function getQueryParamValue(param){
var q = document.location.search;
if (q) {
if (/\?/.test(q)) { q = q.split("?")[1]; } // strip question mark
if (param == null) {
return urlEncodeIfNecessary(q);
}
var pairs = q.split("&");
for (var i = 0; i < pairs.length; i++) {
if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
return urlEncodeIfNecessary(pairs[i].substring((pairs[i].indexOf("=") + 1)));
}
}
}
return "";
}
/*********url=http://localhost/test.html?videoid=1212 ********/
var videoid=getQueryParamValue("videoid");
alert(videoid);//outputs "1212"
</script>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics