亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果未指定自定義字段,我想隱藏 <div> 部分“softdown”

如果未指定自定義字段,我想隱藏 <div> 部分“softdown”

largeQ 2024-01-18 09:49:52
如果未選擇自定義字段或自定義字段為空,我想隱藏 Div 部分!<div class="softdown">  <span class="postdownlink">    <i class="fa fa-download" aria-hidden="true"></i>    <?php echo get_post_meta($post->ID, 'postdownlink', true); ?>  </span></div>
查看完整描述

2 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

在 PHP 中,您可以使用名為 的函數檢查變量是否為空empty。所以,你可以這樣做:


<?php if(!empty($iamempty)){ ?>


<h1>I won't be shown</h1>


<? } ?>

因此,為了將其實現到代碼中,您可以執行以下操作。


<?php if(!empty(get_post_meta($post->ID, 'postdownlink', true))){ ?>


<div class="softdown">

  <span class="postdownlink">

    <i class="fa fa-download" aria-hidden="true"></i>

    <?php echo get_post_meta($post->ID, 'postdownlink', true); ?>

  </span>

</div>


<? } ?>

如果返回的值不為空,上面的代碼將僅顯示 div(標簽之間的 HTML 內容PHP) 。get_post_meta


查看完整回答
反對 回復 2024-01-18
?
侃侃無極

TA貢獻2051條經驗 獲得超10個贊

如果需要實時完成,可以這樣做:


可以將其添加到 JS 文件的頂部:


    var inputChange = function (){

        ($('input#photo').val().length === 0) { 

               // Hide the element  On keyup check the value of the input if length is 0 meaning empty hide the div otherwise show.

               $('div.sofdown').hide(); // Using hide()

               //Or using fadeOut();

               $('div.sofdown').fadeOut(1000);

            }

    }

//Initiate to hide the div if there is no text in input.

inputChange();

之后初始狀態將是hidden


這應該添加到JS文件的末尾


$('input#photo').keyup(function() { 

    //Call function

    inputChange();

}


查看完整回答
反對 回復 2024-01-18
  • 2 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號