0

フォームのユーザー入力から収集されたページにカスタム フィールドがあります。挿入されるたびに 1 つだけ (customfield1customfield2) が挿入されます。またはが空divの場合、全体 (class="customfield")を非表示にする方法がわかりません。別のクラスまたは ID に変更できません。customfield1customfield2customfield

どうもありがとうございました!

<div class="customfield">
    <h4>Custom field title 1</h4>
    <?php if( get_post_meta($post->ID, "customfield1", true) ): ?>
    <?php echo get_post_meta($post->ID, "customfield1", true); ?>
    <?php endif; ?>                     
</div>

<div class="customfield">
    <h4>Custom field title 2</h4>
    <?php if( get_post_meta($post->ID, "customfield2", true) ): ?>
    <?php echo get_post_meta($post->ID, "customfield2", true); ?>
    <?php endif; ?>                     
</div>
4

1 に答える 1

2
$(".customfield").filter(function () {
   return $.trim($('p', this).text()) === '';
}).hide();​

これにより、テキストのない.customfieldを含むすべての要素が非表示になります。<p>

于 2012-12-10T15:43:51.630 に答える