如何通过HTML下拉列表来更改元素?

时间:2013-10-19 14:51:45

标签: javascript html getelementbyid

我目前正在为BlackBerry 10开发eBay应用程序并遇到了问题。问题是,我想要一个下拉菜单(这样用户可以选择他们想要访问哪个易趣国家),但我不知道如何在屏幕底部找到一个按钮以转到正确的页面已在下拉列表中选择一个选项。

http://i1078.photobucket.com/albums/w483/tobster619/Blackberry%2010/help_zps923bcc21.png

这是代码的细分版本,可以在附图中看到:

<script type="text/javascript"> 
//verify the welcome screen 
function verifywelcome(){ 
if (document.getElementById('checkbox').get... == true) { 
alert('checkbox is checked'); 
//set the localstorage item 
localStorage.welcome = "true" ; 
} else if (document.getElementById('checkbox').get... == false) { 
alert('checkbox is not checked'); 
//set the localstorage item 
localStorage.welcome = "false"; 
} 
} 
//if you want to remove the localStorage key to redisplay the welcome screen again.    use: localStorage.removeItem('welcome'); 
function welcome() { 
//check if welcome exists, if not: create it 
if (localStorage.welcome == null) { localStorage.welcome = "true" }; 
if (localStorage.getItem('welcome') == "true") /* if it is true: */ { 
bb.pushScreen('welcome.html', 'welcome'); 
} 
else if (localStorage.getItem('welcome') == "false") { 
bb.pushScreen('menu.html', 'menu'); 
} 
} 

//verify the welcome screen 
function verifywelcome2(){ 
if (document.getElementById('checkbox').get... == true) { 
alert('checkbox is checked'); 
//set the localstorage item 
localStorage.welcome = "true" ; 
} else if (document.getElementById('checkbox').get... == false) { 
alert('checkbox is not checked'); 
//set the localstorage item 
localStorage.welcome = "false"; 
} 
} 


//if you want to remove the localStorage key to redisplay the welcome screen again. use: localStorage.removeItem('welcome'); 
function welcome() { 
//check if welcome exists, if not: create it 
if (localStorage.welcome == null) { localStorage.welcome = "true" }; 
if (localStorage.getItem('welcome') == "true") /* if it is true: */ { 
bb.pushScreen('welcome.html', 'welcome'); 
} 
else if (localStorage.getItem('welcome') == "false") { 
bb.pushScreen('menu2.html', 'menu2'); 
} 
} 
function onLoadFunctions() { 
// Register the app. Make sure you get a unique UUID! 
blackberry.event.addEventListener('ona... function (accessible, status) { 
if (status === 'unregistered') { 
blackberry.bbm.platform.register({ 
uuid: 'b1e606e8-66e5-41db-a932-6ad42f2aa59c' 
}); 
} else if (status === 'allowed') { 
bbm.registered = accessible; 
} 
}, false) 
} 
</script> 

<select id="countryselector"> 
<option value="eBay UK" selected="true" onchange="verifywelcome();bb.pushScreen(...  'Menu');onLoadFunctions();">eBay UK</option> 
<option value="eBay US" "verifywelcome2();bb.pushScreen('menu2.h... 'Menu2');onLoadFunctions();">eBay US</option> 
<option value="eBay CA">eBay CA</option> 
</select> 
<table> 
<tr> 
<td class="cell" style="margin-top:13px;">Show this page on launch</td> 
<td class="cell" ><input id="checkbox" type="checkbox" checked="true" value="one"/>    </td> 
</tr> 
</table> 
<!--BOTTOM PAGE MENU BAR --> 
<div data-bb-type="action-bar"> 
<div data-bb-type="action" data-bb-style="button" data-bb-img="IMG/ic_next.png"  onclick="verifywelcome();bb.pushScreen('... 'Menu');onLoadFunctions();">The Native eBay Experience Awaits...</div> 
</div>  

因此,当用户点击按钮(我刚刚向您展示的代码的最后一部分)时,它会将它们带到eBay UK(menu.html),我的问题是:我如何将其转到如果用户选择eBay US(menu2.html),当他们点击按钮时,它会转到menu2.html(eBay US)而不是menu.html(eBay UK),同时仍允许不同的onclick功能工作( “verifywelcome(); verifywelcome2(); onLoadFunctions();”)?

提前致谢!

1 个答案:

答案 0 :(得分:0)

您可以在onchange级别(而不是select级别)定义option事件,并使选项的值与其对应的相应页面相对应。然后,onchange的处理程序会将按钮的click处理程序设置为document.location = this.value(其中thiscountryselector元素。

我从未在Blackberry DOM中编程,因此我无法编写任何代码。但也许这会给你一个想法。