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