2017-08-08 63 views
-3

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

enter image description here

+2

你得至少尝试写一些代码。简单的答案当然是,是的。但是先尝试一下。 – Difster

+0

你可以给他们每个相同的类,把它们全部放在同一个数组中,然后用它来执行一些操作。但那超出了这个问题的范围。简短的回答是是 – Chris

+0

写一些代码来帮助。 –

回答

0

这对我的作品=)

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'); 
 
    }