Javascript 选择该选项时如何重定向下拉菜单?

Javascript 选择该选项时如何重定向下拉菜单?,javascript,Javascript,当从第三个下拉菜单中选择该选项时,我希望能够跳转到网页 Javascript: var stateObject = { "California": { "Monterey": ["Salinas", "Gonzales"], "Alameda": ["Oakland", "Berkeley"] }, "Oregon": { "Douglas": ["Roseburg", "Winston"], "Jackso

当从第三个下拉菜单中选择该选项时,我希望能够跳转到网页

Javascript:

var stateObject = {
    "California": {
        "Monterey": ["Salinas", "Gonzales"],
        "Alameda": ["Oakland", "Berkeley"]
    },
    "Oregon": {
        "Douglas": ["Roseburg", "Winston"],
        "Jackson": ["Medford", "Jacksonville"]
    }
}
window.onload = function () {
    var stateSel = document.getElementById("stateSel"),
        countySel = document.getElementById("countySel"),
        citySel = document.getElementById("citySel");
    for (var state in stateObject) {
        stateSel.options[stateSel.options.length] = new Option(state, state);
    }
    stateSel.onchange = function () {
        countySel.length = 1; // remove all options bar first
        citySel.length = 1; // remove all options bar first
        if (this.selectedIndex < 1) return; // done   
        for (var county in stateObject[this.value]) {
            countySel.options[countySel.options.length] = new Option(county, county);
        }
    }
    stateSel.onchange(); // reset in case page is reloaded
    countySel.onchange = function () {
        citySel.length = 1; // remove all options bar first
        if (this.selectedIndex < 1) return; // done   
        var cities = stateObject[stateSel.value][this.value];
        for (var i = 0; i < cities.length; i++) {
            citySel.options[citySel.options.length] = new Option(cities[i], cities[i]);
        }
    }
}
var stateObject={
“加利福尼亚”:{
“蒙特利”:[“萨利纳斯”、“冈萨雷斯”],
“阿拉米达”:[“奥克兰”、“伯克利”]
},
“俄勒冈州”:{
“道格拉斯”:[“罗斯堡”、“温斯顿”],
“杰克逊”:[“梅德福德”、“杰克逊维尔”]
}
}
window.onload=函数(){
var stateSel=document.getElementById(“stateSel”),
countySel=document.getElementById(“countySel”),
citySel=document.getElementById(“citySel”);
for(stateObject中的变量状态){
stateSel.options[stateSel.options.length]=新选项(state,state);
}
stateSel.onchange=函数(){
countySel.length=1;//首先删除所有选项栏
citySel.length=1;//首先删除所有选项栏
如果(this.selectedIndex<1)返回;//完成
for(stateObject[this.value]中的var county){
countySel.options[countySel.options.length]=新选项(县,县);
}
}
stateSel.onchange();//重新加载页面时重置
countySel.onchange=函数(){
citySel.length=1;//首先删除所有选项栏
如果(this.selectedIndex<1)返回;//完成
var cities=stateObject[stateSel.value][this.value];
对于(变量i=0;i
HTML:


选择状态


请先选择州

请先选择县

知道如何解决这个问题吗?

添加:

citySel.onchange = function(){
        window.location.href = "http://google.it";
}
window.onload=function()的底部,{
应该完成这项工作

你可能想做一些类似的事情:

citySel.onchange = function(){
switch(citySel.value){
case "Salinas":
        window.location.href = "http://salinas.com";
break;
case "Gonzales":
    if(stateSel.value == "Something"){
        window.location.href = "http://gonzales.com";
    }else if(stateSel.value == "Else"){
        window.location.href = "http://gonzales.com";
    }
break;
}

onchange
处理程序添加到您的城市选择中

var stateObject={
“加利福尼亚”:{
“蒙特利”:[“萨利纳斯”、“冈萨雷斯”],
“阿拉米达”:[“奥克兰”、“伯克利”]
},
“俄勒冈州”:{
“道格拉斯”:[“罗斯堡”、“温斯顿”],
“杰克逊”:[“梅德福德”、“杰克逊维尔”]
}
}
window.onload=函数(){
var stateSel=document.getElementById(“stateSel”),
countySel=document.getElementById(“countySel”),
citySel=document.getElementById(“citySel”);
for(stateObject中的变量状态){
stateSel.options[stateSel.options.length]=新选项(state,state);
}
stateSel.onchange=函数(){
countySel.length=1;//首先删除所有选项栏
citySel.length=1;//首先删除所有选项栏
如果(this.selectedIndex<1)返回;//完成
for(stateObject[this.value]中的var county){
countySel.options[countySel.options.length]=新选项(县,县);
}
}
stateSel.onchange();//重新加载页面时重置
countySel.onchange=函数(){
citySel.length=1;//首先删除所有选项栏
如果(this.selectedIndex<1)返回;//完成
var cities=stateObject[stateSel.value][this.value];
对于(变量i=0;i0&&countySel.options.length){
警报('County:'+countySel.value+'-状态:'+stateSel.value+'-城市:'+citySel.value%);
location.href='/';//您的链接
}
}
}

选择状态


请先选择州

请先选择县
以下行可用于选择框的
onChange
事件:

window.location.replace("http://YOUR-URL-HERE.com");
var stateObject={
“加利福尼亚”:{
“蒙特利”:[“萨利纳斯”、“冈萨雷斯”],
“阿拉米达”:[“奥克兰”、“伯克利”]
},
“俄勒冈州”:{
“道格拉斯”:[“罗斯堡”、“温斯顿”],
“杰克逊”:[“梅德福德”、“杰克逊维尔”]
}
}
window.onload=函数(){
var stateSel=document.getElementById(“stateSel”),
countySel=document.getElementById(“countySel”),
citySel=document.getElementById(“citySel”);
for(stateObject中的变量状态){
stateSel.options[stateSel.options.length]=新选项(state,state);
}
stateSel.onchange=函数(){
countySel.length=1;//首先删除所有选项栏
citySel.length=1;//首先删除所有选项栏
如果(this.selectedIndex<1)返回;//完成
for(stateObject[this.value]中的var county){
countySel.options[countySel.options.length]=新选项(县,县);
}
}
stateSel.onchange();//重新加载页面时重置
countySel.onchange=函数(){
citySel.length=1;//首先删除所有选项栏
如果(this.selectedIndex<1)返回;//完成
var cities=stateObject[stateSel.value][this.value];
对于(变量i=0;i

选择状态


请先选择州

请先选择县
您的问题不清楚,是您需要帮助或打开网页的下拉菜单吗?您能澄清一下您的意思并提供一些示例代码或示例吗?我需要添加重定向功能,以便在您选择城市时将其重定向到网页。
{uri:'http://msn.com,text:['someText']}更好的是
TextLink(link,text){this.li
window.location.replace("http://YOUR-URL-HERE.com");