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

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();
}
添加回答
舉報