2012-12-27 51 views
-4

請我想編輯此腳本:編輯此下拉的JavaScript

我想刪除點擊後出現的彈出框,我只是希望它重定向到指定的URL,當有人點擊按鈕?

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <script type="text/javascript"> 
     var citiesByState = { 
      "USA": ["NY","NJ"], 
      "Singapore": ["taas","naas"] 
     } 
     var navURLs = { 
      "USA": {"NY": "http://www.yahoo.com","NJ": "http://www.google.com"}, 
      "Singapore": {"taas": "http://www.bing.com","naas": "http://www.ibm.com"} 
     } 
     function makeSubmenu(value) { 
      if(value.length==0) document.getElementById("citySelect").innerHTML = "<option></option>"; 
      else { 
       var citiesOptions = ""; 
       for(cityId in citiesByState[value]) { 
        citiesOptions+="<option>"+citiesByState[value][cityId]+"</option>"; 
       } 
       document.getElementById("citySelect").innerHTML = citiesOptions; 
      } 
     } 
     function displaySelected() { 
      var country = document.getElementById("countrySelect").value; 
      var city = document.getElementById("citySelect").value; 
      alert(country+"\n"+city); 
      navURL = navURLs[country][city]; 
      if(navURL){ 
       alert(navURL);      
       window.location.href = navURL; 
      } 
     } 
     function resetSelection() { 
      document.getElementById("countrySelect").selectedIndex = 0; 
      document.getElementById("citySelect").selectedIndex = 0; 
     } 
    </script> 
</head> 
<body onload="resetSelection()"> 
    <select id="countrySelect" size="1" onchange="makeSubmenu(this.value)"> 
     <option></option> 
     <option>USA</option> 
     <option>Singapore</option> 
    </select> 
    <select id="citySelect" size="1"> 
     <option></option> 
    </select> 
    <button onclick="displaySelected()">show selected</button> 
</body> 
</html> 

請幫助或至少給我一個腳本,做這個

+2

[你嘗試過什麼?](http://www.whathaveyoutried.com/) – Cerbrus

+0

你想擁有哪個按鈕重定向到哪個URL? –

+1

_Adding_代碼相當棘手,但_removing_代碼?這只是微不足道的。我說你只是懶惰。 – Bojangles

回答

1

從該塊刪除警報:

if(navURL){ 
    alert(navURL);      
    window.location.href = navURL; 
} 

所以,這將是:

if(navURL){      
    window.location.href = navURL; 
} 
0

「我想刪除點擊「後出現的彈出框,你的意思是,警報?只要刪除包含任何alert()的行。

0

試試這個

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <script type="text/javascript"> 
     var citiesByState = { 
      "USA": ["NY","NJ"], 
      "Singapore": ["taas","naas"] 
     } 
     var navURLs = { 
      "USA": {"NY": "http://www.yahoo.com","NJ": "http://www.google.com"}, 
      "Singapore": {"taas": "http://www.bing.com","naas": "http://www.ibm.com"} 
     } 
     function makeSubmenu(value) { 
      if(value.length==0) document.getElementById("citySelect").innerHTML = "<option></option>"; 
      else { 
       var citiesOptions = ""; 
       for(cityId in citiesByState[value]) { 
        citiesOptions+="<option>"+citiesByState[value][cityId]+"</option>"; 
       } 
       document.getElementById("citySelect").innerHTML = citiesOptions; 
      } 
     } 
     function displaySelected() { 
      var country = document.getElementById("countrySelect").value; 
      var city = document.getElementById("citySelect").value; 
      //alert(country+"\n"+city); 
      navURL = navURLs[country][city]; 
      if(navURL){ 
       //alert(navURL);      
       window.location.href = navURL; 
      } 
     } 
     function resetSelection() { 
      document.getElementById("countrySelect").selectedIndex = 0; 
      document.getElementById("citySelect").selectedIndex = 0; 
     } 
    </script> 
</head> 
<body onload="resetSelection()"> 
    <select id="countrySelect" size="1" onchange="makeSubmenu(this.value)"> 
     <option></option> 
     <option>USA</option> 
     <option>Singapore</option> 
    </select> 
    <select id="citySelect" size="1"> 
     <option></option> 
    </select> 
    <button onclick="displaySelected()">show selected</button> 
</body> 
</html> 
+0

@ theMarceloR:註釋行號28和31中刪除所有可見的'alert'框。 –