简体   繁体   English

如何获得一个保管箱以显示另一个保管箱中的选项

[英]How to get a dropbox to show options in another dropbox

I was thinking if it's possible to let a select dropdown box deside which options there will be in another select dropbox. 我在想是否可以让一个选择下拉框忽略另一个选择下拉框中的选项。

For example, i would like to have a checkbox, if that's checked a dropbox will appear. 例如,我想要一个复选框,如果选中该复选框,则会出现一个下拉框。 And when choosing an option i that dropbox, a new dropbox would appear. 当选择该保管箱选项时,将出现一个新的保管箱。

Then if i have choosed days, in the first dropbox, then i would be able to choose between all days of the week in the new dropbox. 然后,如果我在第一个保管箱中选择了几天,那么我将可以在新保管箱的一周中的所有天之间进行选择。 Then if i choose weeks, in the first dropbox, then i would be able to choose between all weeks numbers in the new dropbox. 然后,如果我在第一个保管箱中选择周,则可以在新保管箱的所有周数之间进行选择。 And so on.. 等等..

I have tried to google it, but without any luck. 我试图用谷歌搜索它,但是没有任何运气。 The first part with the checkbox and getting the frist dropbox appears is easy enough, but the last part, not so much for me. 带有复选框的第一部分和出现第一个下拉框很容易,但是最后一部分对我而言并没有那么多。

Sorry if my english is bad and my question is a little hard to understand. 抱歉,如果我的英语不好,我的问题有点难以理解。

Edit: 编辑:

 <script> function showSelect() { var checkBox = document.getElementById("checked"); var select = document.getElementById("select"); if (checkBox.checked == true){ select.style.display = "block"; } else { select.style.display = "none"; } } </script> Rot: <input type="checkbox" id="checked" onclick="showSelect()"> <select id="select" style="display:none"> <option disabled="disabled" selected="">-- choose --</option> <option value="1">Days</option> <option value="2">Week</option> </select> 

You can do that by listening for a change event on the first select drop down list. 您可以通过在第一个选择下拉列表上侦听change事件来做到这一点。 Once you get the selected value, you can use it with another if statement to display the next select list. 获得所选值后,可以将其与另一个if语句一起使用以显示下一个选择列表。 Try this: 尝试这个:

 function showSelect() { var checkBox = document.getElementById("checked"); var select = document.getElementById("select"); if (checkBox.checked == true){ select.style.display = "block"; } else { select.style.display = "none"; } } var daysWeeks = document.getElementById('select'), days = document.getElementById('select-days'), weeks = document.getElementById('select-weeks'); daysWeeks.addEventListener('change', function() { var newSelect = daysWeeks.options[daysWeeks.selectedIndex].value; days.style.display = 'none'; weeks.style.display = 'none'; if (newSelect === '1') { days.style.display = 'block'; } else if (newSelect === '2') { weeks.style.display = 'block'; } }); 
 Rot: <input type="checkbox" id="checked" onclick="showSelect()"> <select id="select" style="display:none"> <option disabled="disabled" selected="">-- choose --</option> <option value="1">Days</option> <option value="2">Week</option> </select> <select id="select-days" style="display:none"> <option disabled="disabled" selected="">-- choose --</option> <option value="1">Day1</option> <option value="2">Day2</option> </select> <select id="select-weeks" style="display:none"> <option disabled="disabled" selected="">-- choose --</option> <option value="1">Week1</option> <option value="2">Week2</option> </select> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM