该脚本从组合框中获取选择,并使用所选值重定向到特定路径并打开选定的网页。可变路径不工作的Window.location
function redirect(){
var obj = document.getElementById("cat"); //
var obj2= document.getElementById("sub1");
var obj3= document.getElementById("sub2");
var redir2=obj2.options[obj2.selectedIndex].text.substring(0,4);
var redir =obj.options[obj.selectedIndex].text.substring(0,4); //
var redir3 =obj3.options[obj3.selectedIndex].text.replace(/ /g,"_");
var url= redir+"/"+redir2+"/"+redir3+".php";
url=url.toLowerCase();
alert(url);
window.location.href = "np/categories/"+url;}
由于某些特殊原因,在监视firefox上的日志时,它有时会运行路径,有时它不会。
无论哪种方式,它从不加载选择的页面。 (测试路径和页面都存在)。有时候我在Mozilla网络控制台状态绿灯,这样
GET http://localhost/np/cat/auto/serv/testingpage.php [HTTP/1.1 200 OK 0毫秒]
它从来没有真正加载页面。 我该如何解决这个问题?
究竟会be'url'看起来像? – brk
添加一些输入样本 – iceDragon
redirect()函数应该在某个事件中调用。 –