-1
Q
依赖下拉选择
A
回答
0
通常,当您需要根据下拉列表更改某些内容时,请使用onchange事件。例如:
<select id="standardSelectId" onchange="fillSection(this)">...</select>
<select id="sectionSelectId" onchange="fillSubject(this)"><option>-- Select Standard first --</option></select>
<select id="subjectSelectId"><option>-- Select Section first --</option></select>
然后,写JavaScript函数以填充下一个选择的选项,并清除依赖于下一个选择的任何选择:
<script type="text/javascript">
function fillSection(e) {
var choice = e.options[e.selectedIndex];
var sectionSelect = document.getElementById("sectionSelectId");
var subjectSelect = document.getElementById("subjectSelectId");
subjectSelect.options.length = 0;
try { subjectSelect.add(new Option("-- Select Section first --", ""))} catch(ex) {subjectSelect.add(new Option("-- Select Section first --", ""), null)}
sectionSelect.options.length = 0;
switch (choice.value) {
case <standard val1>:
try { sectionSelect.add(new Option(section1_label_1, section1_key_1))} catch(ex) {subjectSelect.add(new Option(section1_label_1, section1_key_1), null)}
...
try { sectionSelect.add(new Option(section1_label_N, section1_key_N))} catch(ex) {subjectSelect.add(new Option(section1_label_N, section1_key_N), null)}
break;
case <standard valX>:
try { sectionSelect.add(new Option(sectionX_label_1, sectionX_key_1))} catch(ex) {subjectSelect.add(new Option(sectionX_label_1, sectionX_key_1), null)}
...
try { sectionSelect.add(new Option(sectionX_label_N, sectionX_key_N))} catch(ex) {subjectSelect.add(new Option(sectionX_label_N, sectionX_key_N), null)}
break;
}
function fillSubject(e) {
...
}
相关问题
- 1. 多个选择下拉依赖于另一个下拉选项值
- 2. Django:依赖下拉
- 3. JavaScript依赖下拉
- 4. 依赖下拉列表不会加载选择第一个下拉列表
- 5. 下拉依赖于yii框架中的多选择下拉列表
- 6. 填充依赖于更改事件的选择下拉列表
- 7. 依赖下拉选择使用AJAX的codeigniter
- 8. 的Rails 3.1相互依赖选择下拉列表
- 9. 如何在yii2中创建依赖选择2下拉菜单?
- 10. Bootstrap下拉菜单选择依赖关系
- 11. Vue.js依赖选择
- 12. Yii依赖下拉列表
- 13. zend形式依赖下拉
- 14. HTML依赖下拉菜单
- 15. Joomla内部依赖下拉
- 16. jQuery依赖选择选项
- 17. jQuery依赖选择选项
- 18. 主动管理员根据第一次下拉选择下降依赖负载
- 19. jQuery依赖选择框(选择)
- 20. 流星依赖选择
- 21. Maven依赖关系选择
- 22. 选择依赖于@RequestParam
- 23. MySQL的选择依赖于
- 24. 下拉选择
- 25. 选择用1万点美元的期权,啊哈...依赖下拉元太
- 26. 如何添加从另一个依赖的选择下拉菜单?
- 27. 创建依赖下拉列表
- 28. 下拉列表依赖形式
- 29. Yii2依赖下拉数据不显示
- 30. 依赖Aurelia的下拉列表?