简体   繁体   English

隐藏多个表单字段并防止空白

[英]hide multiple form fields and preventing white space

I have a booking form im trying to create, which involves a jquery datepicker and a few dropdown lists. 我有一个尝试创建的预订表单,其中涉及一个jquery datepicker和一些下拉列表。 I want to give the user the option of choosing a date from the calendar, then either hide or show several dropdown lists below it based on the DAY they have chosen in the calendar. 我想为用户提供从日历中选择日期的选项,然后根据他们在日历中选择的日期隐藏或显示其下方的几个下拉列表。 Each of the dropdown lists are presented one after the other, but are all hidden until the user makes a selection in the datepicker. 每个下拉列表都一个接一个显示,但是全部隐藏,直到用户在日期选择器中进行选择为止。 There is one dropdown list for each day, with different options. 每天都有一个下拉列表,有不同的选项。

I can get the form to show / hide each dropdown list based on the users selection in the datepicker, but the problem I have is with each different choice, the corresponding dropdown box shuffles down the page, based on where the actual dropdown list sits. 我可以获取基于日期选择器中的用户选择显示/隐藏每个下拉列表的表单,但是我遇到的问题是每个不同的选择,相应的下拉框会根据实际下拉列表所在的位置对页面进行随机排序。

How do I make it so that no mater what dropdown list is shown, it is always displayed on the same row? 我该如何做,以确保不再显示任何下拉列表,而是始终显示在同一行? if that makes sense? 那有道理吗?

HTML Form: HTML表单:

             <input type="text" id="datepicker" />
             <div class="hide" id="hide1">
      <div class="input select">
              <select name="select1" id="Monday">
              <option value="1" selected="selected">(Monday)</option>
              <option value="2">10am - 12pm</option>
              <option value="3">1pm - 3pm</option>
              </select>
            </div></div>
            <br />
            <div class="hide" id="hide2">
      <div class="input select">
              <select name="select2" id="Tuesday">
              <option value="1" selected="selected">(Tuesday)</option>
              <option value="2">10am - 3pm</option>
              <option value="3">7:30pm - 10pm</option>
              </select>
            </div></div>
            <br />
            <div class="hide" id="hide3">
      <div class="input select">
              <select name="select3" id="Wednesday">
              <option value="1" selected="selected">(Wednesday)</option>
              <option value="2">10am - 3pm</option>
              </select>
            </div></div>
            <br />
            <div class="hide" id="hide4">
      <div class="input select">
              <select name="select4" id="Thursday">
              <option value="1" selected="selected">(Thursday)</option>
              <option value="2">10am - 3pm</option>
              </select>
            </div></div>
            <br />
           <div class="hide" id="hide5">
      <div class="input select">
              <select name="select5" id="Friday">
              <option value="1" selected="selected">(Friday)</option>
              <option value="2">1pm - 3pm</option>
              <option value="3">4pm - 6pm</option>
              <option value="4">7:30pm - 10pm</option>
              </select>
            </div></div>
            <br />
            <div class="hide" id="hide6">
      <div class="input select">
              <select name="select6" id="Saturday">
              <option value="1" selected="selected">(Saturday)</option>
              <option value="3">1:30pm - 3:30pm</option>
              <option value="4">8pm - 10pm</option>
              </select>
            </div></div>
            <div class="hide" id="hide7">
      <div class="input select">
              <select name="select7" id="Sunday">
              <option value="1" selected="selected">(Sunday)</option>
              <option value="2">10am - 12pm</option>
              <option value="3">1:30pm - 3:30pm</option>
              </select>
            </div></div>

jquery function to hide / show the dropdown lists jQuery函数隐藏/显示下拉列表

      $(document).ready(function(){
$("#datepicker").change(function(){

    if ($(this).val() == "Monday" ) {

        $("#hide1").slideDown("fast"); //Slide Down Effect


    } else {


        $("#hide1").slideUp("fast"); //Slide Down Effect

    } 

    if ($(this).val() == "Tuesday" ) {

        $("#hide2").slideDown("fast"); //Slide Down Effect


    } else {


        $("#hide2").slideUp("fast"); //Slide Down Effect

    } 

    if ($(this).val() == "Wednesday" ) {

        $("#hide3").slideDown("fast"); //Slide Down Effect


    } else {


        $("#hide3").slideUp("fast"); //Slide Down Effect

    } 

    if ($(this).val() == "Thursday" ) {

        $("#hide4").slideDown("fast"); //Slide Down Effect


    } else {


        $("#hide4").slideUp("fast"); //Slide Down Effect

    } 

            if ($(this).val() == "Friday" ) {

        $("#hide5").slideDown("fast"); //Slide Down Effect


    } else {


        $("#hide5").slideUp("fast"); //Slide Down Effect

    } 

            if ($(this).val() == "Saturday" ) {

        $("#hide6").slideDown("fast"); //Slide Down Effect


    } else {


        $("#hide6").slideUp("fast"); //Slide Down Effect

    } 

            if ($(this).val() == "Sunday" ) {

        $("#hide7").slideDown("fast"); //Slide Down Effect


    } else {


        $("#hide7").slideUp("fast"); //Slide Down Effect

    } 

});

}); });

Not entirely sure what you are having trouble with. 不完全确定您遇到了什么问题。 Anyway, I created this jsfiddle with your html & js. 无论如何,我用您的html和js创建了这个jsfiddle I removed the br html tags and added the hide css class definition. 我删除了br html标签,并添加了hide css类定义。

 .hide { display: none;}

The dropdowns all appear on the row just beneath the datepicker input. 下拉菜单均显示在datepicker输入下方的行中。

But, like I said, not entirely sure of your goal here :-) 但是,就像我说的那样,这里并不完全确定您的目标:-)

HTH. HTH。

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

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