如何使用 HTML 中的下拉列表更改元素
How to get an element to change with a dropdown in HTML?
我目前正在为黑莓10开发eBay应用程序,遇到了一个问题。问题是,我想要一个下拉菜单(以便用户可以选择他们想要访问的 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)而不是菜单.html(eBay UK),同时仍然允许不同的onclick功能来改变work ("verifywelcome();verifywelcome2();onLoadFunctions();")?
提前感谢!
您可以在
select
级别(而不是option
级别)定义onchange
事件,并使选项的值成为它们对应的相应页面。然后,onchange
处理程序会将按钮的click
处理程序设置为类似于document.location = this.value
(其中this
是countryselector
元素。
我从来没有用过黑莓DOM编程,所以我不能写任何代码。但也许这给了你一个想法。
相关文章:
- 如何在按钮中显示下拉列表中选定的元素
- 使用Razor和javascript来获得下拉列表元素
- 将onclick事件附加到具有一个元素的下拉列表中
- 保持元素处于禁用状态,直到未在 Angularjs 中选择下拉列表
- 根据下拉列表中选择的项目隐藏所有元素
- 将同一个元素追加到两个下拉列表中只会导致最后一个元素被追加
- 如何在输入框中只显示名称,而在选择元素的下拉列表中显示名称和数字
- 如何使下拉列表展开单击按钮元素
- 根据下拉列表中选择的内容隐藏和显示 HTML 元素
- 下拉列表使元素移动
- 选择其他字段元素时如何重置选择选项下拉列表
- 未在选择标记下拉列表中选择以隐藏其他输入元素的嵌套控制器
- 单击其他元素(文本输入)时显示下拉列表
- 剑道UI [下拉列表] - 多个元素中的冲突
- 如何使用 HTML 中的下拉列表更改元素
- JavaScript - 如何检测选择元素上的编程值更改(下拉列表)
- 隐藏“选择”下拉列表的元素
- jQuery 下拉列表 将鼠标悬停在两个不同的元素上
- 在选择框(下拉列表)中检查元素 ID 值
- JqueryUI 工具提示可防止<选择>元素下拉列表在 IE 11 中保持关闭