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

来源:百度知道 编辑:UC知道 时间:2024/06/01 13:44:05
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>

假设URL的地址是 http://localhost/test.html?player=shamohai

<script>