html怎么样获得URL的变量,送100高分

news.htm?q=123456
怎么样在news.htm里获得这个q的变量值。

以下是素材
<INPUT name=key id=kw > 这个文本域默认就能显示出q变量的值,但是我想这个变量值显示在<TITLE></TITLE>里
<script>var w=document.f.key;w.focus();function s(o){if(w.value.length>0){var h=o.href;var q=encodeURIComponent(w.value);if(h.indexOf("q=")!=-1){o.href=h.replace(new RegExp("q=[^&$]*"),"q="+q)}else{o.href+="?q="+q}}};(function(){if(new RegExp("q=([^&]+)").test(location.search)){w.value=decodeURIComponent(RegExp.$1)}})()
</script>

演示地址
http://localhost/1.html?newsid=getid

你把下面一段代码复制到html页面里试试
------------------------------------------------------------------

<script>
urlinfo=window.location.href; //获取当前页面的url
len=urlinfo.length;//获取url的长度
offset=urlinfo.indexOf("?");//设置参数字符串开始的位置
newsidinfo=urlinfo.substr(offset,len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
newsids=newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割
newsid=newsids[1];//得到参数值
alert("您要传递的参数值是"+newsid);
response.write(newsid);
</script>
<html>
<body>
<script>document.write(newsid);</script>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-12-23
假设URL的地址是

<script>

var add = top.location;//取得地址栏的URL
add = add.toString();
var showIndex = add.indexOf("?player=");//得到参数的位置

var showParam="";//需要得到的参数

if (playerIndex != -1) {
showParam= unescape(add.substring(playerIndex + 8, add.length));

}

</script>

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网