跳转菜单能获取地址栏参数吗?该怎么处理
跳转菜单能获取地址栏参数吗?
<select onchange="document.location = this[this.selectedIndex].id;">
<option selected>请选择</option>
<option id="?n=1&t=<%=Request("t")%>">第一项</option>
<option id="?n=2&t=<%=Request("t")%>">第二项</option>
</select>
比如,当前页面为index.asp?t=111
跳转后缺少参数t,直接转到了:“index.asp?n=1&t=”或“index.asp?n=2&t=”,option中的<%=Request("t")%>根本就没有起作用。
请问怎样在option中获取地址栏参数t?
------解决方案--------------------
<%
Dim t
t=Request("t")
%>
<script language="JavaScript">
<!--
function select1_Change() {
location.replace("TestLocation.asp?n="+select1.value+"&t=<%=t%>");
}
//-->
</script>
<body>
<select name="select1" onchange="select1_Change()">
<option selected>请选择</option>
<option value="1">第一项</option>
<option value="2">第二项</option>
</select>
------解决方案--------------------
<select onchange="document.location = this[this.selectedIndex].id;">
<option selected>请选择</option>
<option id="?n=1&t=<%=Request("t")%>">第一项</option>
<option id="?n=2&t=<%=Request("t")%>">第二项</option>
</select>
比如,当前页面为index.asp?t=111
跳转后缺少参数t,直接转到了:“index.asp?n=1&t=”或“index.asp?n=2&t=”,option中的<%=Request("t")%>根本就没有起作用。
请问怎样在option中获取地址栏参数t?
------解决方案--------------------
<%
Dim t
t=Request("t")
%>
<script language="JavaScript">
<!--
function select1_Change() {
location.replace("TestLocation.asp?n="+select1.value+"&t=<%=t%>");
}
//-->
</script>
<body>
<select name="select1" onchange="select1_Change()">
<option selected>请选择</option>
<option value="1">第一项</option>
<option value="2">第二项</option>
</select>
------解决方案--------------------
- HTML code
<script type='text/javascript'> RegExp.escape = function(str) { return (str||'').replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); }; function changeParam(name, value) { name = encodeURIComponent(name); var p = name + "=" + encodeURIComponent(value); var href = location.href; if (!/\?/.test(href)) return location.href = href.replace(/[^?&=#]+/, '$&?' + p); if (new RegExp("\\b" + RegExp.escape(name) + "=", "ig").test(href.split("?")[1])) return location.href = href.replace(new RegExp("\\b" + RegExp.escape(name) + "\\=[^&#]*", "ig"), p); return location.href = href.replace(/[^?&=#]+\?/, '$&' + p + "&"); } </script> <select name="select1" onchange="changeParam('n', this.value)"> <option selected>请选择</option> <option value="1">第一项</option> <option value="2">第二项</option> </select>
------解决方案--------------------
測試過樓主的代碼沒有問題喔