我希望当单击按钮时,下拉菜单中的某些值稍后会出现在同一文档中。
例如,如果有一个名为本田的按钮,单击它会将下拉菜单中的内容更改为汽车的型号详细信息。
如何才能做到这一点?
上下文:启用 PHP 的服务器上的网页
提前致谢!
最佳答案
我建议最简单的解决方案是 JavaScript。使用框架来完成如此简单的任务似乎重载:
<html>
<head><title>JS example</title></head>
<body>
<script type="text/javascript"><!--
//
var opt_one = new Array('blue', 'green', 'red');
var opt_two = new Array('plaid', 'paisley', 'stripes');
//
function updateTarget() {
var f = document.myform;
var which_r = null;
if (f) {
// first option selected? ("One")
if (f.trigger.value == '1') {
which_r = opt_one;
// ...or, second option selected? ("Two")
} else if (f.trigger.value == '2') {
which_r = opt_two;
// no known option, hide the secondary popup
} else {
f.target.style.display = 'none';
}
// did we find secondary options for the selection?
if (which_r) {
// reset/clear the target pop-up
f.target.innerHTML = '';
// add each option
for (var opt in which_r) {
f.target.innerHTML += '<option>' + which_r[opt] + '</option>';
}
// display the secondary pop-up
f.target.style.display = 'inline';
}
}
} // updateTarget()
//-->
</script>
<form name="myform" action="#">
<select name="trigger" onchange="updateTarget();">
<option>Select one...</option>
<option>-</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<select name="target" style="display:none;">
</select>
</form>
</body>
</html>
关于php - 单击按钮如何更改下拉菜单的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1131766/