2016-09-29 17 views
0

私はPHPに慣れていないので、私の問題を解決するための助けが必要です。phpドロップダウンオプションの値が0の場合、divを非表示にする

私はPHPのスニペットを貼り付け、私は編集が必要だと信じています。

<div class="selectBox" id="products-variation-container"> 
    <select class="product-variation-dropdown" name="product-variation" id="sel-product-variation"> 
    <option value="0"><?php _e('Select variation', 'wp-woo-leasing'); ?></option> 
    </select> 
</div> 

<!-- <input type="submit" name="btn-submit" class="button alt" id="leasingAddItem" value="<?php _e('Add Item', 'wp-woo-leasing'); ?>" 
    data-value="<?php _e('Add Item', 'wp-woo-leasing'); ?>" />--> 

</div> 
</div> 
<div class="leasing-single-container" > 
    <div class="leasing-col1" > 
     <div id="product-description" class="product-description"></div> 
     <div id="product-price-details" class="product-price-details"></div> 
    </div> 

私の問題は、私は私のコードは次のようになりたいということです。デフォルト値は0であるため、オプション値=「0」は、その後、積載サイト時に、次のdivを非表示にした場合

<select class="product-variation-dropdown" name="product-variation" id="sel-product-variation"> 
    <option value="0"><?php _e('Select variation', 'wp-woo-leasing'); ?> 

<div id="product-description" class="product-description"></div> 

私の質問を理解していただければ幸いです。ありがとうございました。

+0

..代わりにこのようなものを使用できます。代わりに0を試す –

+0

は条件文または3項演算子を使用します。後者はより合理化されたソリューションです –

+0

私はあなたの質問を得ることはありません、値0のオプションが選択されたときdivを非表示にしたいのですか、または選択されたオプションの値が0の場合divを非表示にするには? – Epodax

答えて

0

jQueryを使用して、選択値に基づいてdivを表示および非表示にできます。

Wordpressにはすでにjqueryファイルが含まれているため、追加する必要はありません。 (https://developer.wordpress.org/reference/functions/wp_enqueue_script/)。ここで

は、使用できるコードです:

<div class="selectBox" id="products-variation-container"> 
    <select class="product-variation-dropdown" name="product-variation" id="sel-product-variation" onchange="getval();"> 
<option value="0">Select Option</option> 
<option value="1">Select Option1</option> 
</select> 
</div> 
<div class="leasing-single-container" > 
<div class="leasing-col1" > 
    <div id="product-description" class="product-description">dgsdgsdgsdgsdgsd</div> 
    <div id="product-price-details" class="product-price-details"></div> 
</div> 
</div> 

<script> 
    jQuery(document).ready(function() { 
      var sel = jQuery('select[name=product-variation]').val(); 
      if(sel == 0) { 
        jQuery('#product-description').attr('style', 'display:none'); 
      } 
      jQuery('#sel-product-variation').on('change', function() { 
       var sel = jQuery('select[name=product-variation]').val(); 
        if(sel == 0) { 
          jQuery('#product-description').attr('style', 'display:none'); 
        } 
        else { 
          jQuery('#product-description').attr('style', 'display:block'); 
        } 
      }); 

    }); 
</script> 

は私が同じのための任意の懸念の包みを教えてください。

関連する問題