2017-08-08 15 views
-3

時間帯に基づいてフォームの選択フィールドを非表示にすることはできますか?選択オプションの非表示時間を

enter image description here

+2

あなたはいくつかのコードを書くための少なくとも試みを持っています。短い答えは、もちろん、はいです。しかしまずそれを試してみてください。 – Difster

+0

それぞれに同じクラスを与え、同じ配列内にそれらをすべてグループ化し、それを使っていくつかの操作を実行できます。しかし、それはこの質問の範囲を超えています。短い答えはyesです – 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'); 
 
    }

関連する問題