JavaScript中如何重定向url?

xian_yun80 2008-10-13 09:38:57
我现在有两个不同的文件夹,分别用月份命名,里面的文件名相同。
在HTML页面上有个select标签,绑定的是不同的月份,
我如何能够在选择select标签中的内容后,点击button,跳转到另一个文件夹下面的与该页面相同的url上呢?
...全文
537 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
YBYQNO1 2008-10-13
  • 打赏
  • 举报
回复
我支持6楼的看法
wdbjsh 2008-10-13
  • 打赏
  • 举报
回复
顶楼上,差不多就这样了
2008-10-13
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function calu(){
var url = window.location.href;
var month = $("permonth").options[$("permonth").selectedIndex].value;
month = month.length < 2 ? "0" + month : month;
url = url.replace(/(^.*\/20\d{2})(\d{2})(\d{2}\/.*.htm[l]$)/, "$1" + month + "$3");
window.location.href = url;
}
</script>

<select id="permonth" name="permonth">
<option value="9" selected="selected">2008年9月</option>
<option value="8">2008年8月</option>
</select>
<input type="submit" name="submit" value="查询" onclick="calu()" />

</body>
</html>


xian_yun80 2008-10-13
  • 打赏
  • 举报
回复
我alert出来地址了,地址是正确的。可跳转不了,报url不正确.我的html是aspx自动生成的。郁闷!
pingxizhang 2008-10-13
  • 打赏
  • 举报
回复
在option后面加一个value,然后用js判断实现跳转就可以了吧
xian_yun80 2008-10-13
  • 打赏
  • 举报
回复
可能我刚才没说清楚:

查询其他月份:
<select id="permonth" name="permonth">
<option value="9" selected="selected">2008年9月</option>
<option value="8">2008年8月</option>
</select>
<input type="submit" name="submit" value="查询" onclick="calu()" />

当前页面如果是../20080930/a1.html
我选择2008年8月时,我想让它跳到../20080831/a1.html
hsx85315 2008-10-13
  • 打赏
  • 举报
回复
楼上正解,再加一个document.location.href="构造的URL";
dln1234 2008-10-13
  • 打赏
  • 举报
回复
你把时间当成1个变量
比如200808.html ,200809.html
select的ID是sel_id
var abc=document.getElementId("sel_id").value;
var url=abc+".html";
fengzilingzi 2008-10-13
  • 打赏
  • 举报
回复
是说跳到另外一个网页过滤条件相同的东西吧
tjgjp 2008-10-13
  • 打赏
  • 举报
回复
我看不出楼主的所要表达的意思,在详细说明。最好举个详细的例子
xian_yun80 2008-10-13
  • 打赏
  • 举报
回复
两个不同的文件夹,但是里面的文件名相同
比如说我现在200808/a.html这个文件上,我想跳到200809/a.html上.
cloudgamer 2008-10-13
  • 打赏
  • 举报
回复
文件夹?

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧