【问题标题】:Hide select option based hour of the day隐藏基于一天中的小时的选择选项
【发布时间】:2018-01-16 12:16:11
【问题描述】:

是否可以根据一天中的时间隐藏表单的选择字段?

【问题讨论】:

  • 您至少必须尝试编写一些代码。简短的回答当然是肯定的。不过先自己试试吧。
  • 你可以给它们每个相同的类,将它们全部分组到同一个数组中,然后用它执行一些操作。但这超出了这个问题的范围。简短的回答是肯定的
  • 写一些代码来帮忙。

标签: javascript html select


【解决方案1】:

这对我有用 =)

var d = new Date();
    
    var h = d.getHours();
    var m = d.getMinutes();   
   
   if(h==10){
     if(m<=30){
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     }
     else{
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     }

   }
   else if(h==11){
     if(m<=30){
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     
     }
     else{
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(5)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("disabled",'disabled');
     }   
   }
   else if(h==12){
     if(m<=30){
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(6)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(5)').attr("disabled",'disabled');
     
     }
     else{
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(7)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(5)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(6)').attr("disabled",'disabled');
     }   
   }
   else if(h==13){
     if(m<=30){
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(8)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(5)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(6)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(7)').attr("disabled",'disabled');
     
     }
     else{
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(9)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(5)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(6)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(7)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(8)').attr("disabled",'disabled');
     }   
   }
   else if(h==14){
     if(m<=30){
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(10)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(5)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(6)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(7)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(8)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(9)').attr("disabled",'disabled');
     
     }
     else{
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
     jQuery('#order_wcj_checkout_field_3 option:nth-child(11)').attr("selected",'selected');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(2)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(3)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(4)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(5)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(6)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(7)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(8)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(9)').attr("disabled",'disabled');
     jQuery('#order_wcj_checkout_field_3 option:nth-child(10)').attr("disabled",'disabled');
     }   
   }
   else if(h>=15){
   jQuery('#order_wcj_checkout_field_3 option:nth-child(10)').attr("disabled",'disabled');
   jQuery('#order_wcj_checkout_field_3').append("<option value='00'>Hoje acabou. Compre com agendamento amanhã.</option>");
   jQuery('#order_wcj_checkout_field_3 option:nth-child(1)').removeAttr("selected");
   jQuery('#order_wcj_checkout_field_3 option:nth-child(11)').attr("selected",'selected');
   }

【讨论】:

    猜你喜欢
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多