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

如果未选择自定义字段或自定义字段为空,我想隐藏 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>


largeQ
浏览 101回答 2
2回答

有只小跳蛙

在 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">&nbsp; <span class="postdownlink">&nbsp; &nbsp; <i class="fa fa-download" aria-hidden="true"></i>&nbsp; &nbsp; <?php echo get_post_meta($post->ID, 'postdownlink', true); ?>&nbsp; </span></div><? } ?>如果返回的值不为空,上面的代码将仅显示 div(标签之间的 HTML 内容PHP) 。get_post_meta

侃侃无极

如果需要实时完成,可以这样做:可以将其添加到 JS 文件的顶部:&nbsp; &nbsp; var inputChange = function (){&nbsp; &nbsp; &nbsp; &nbsp; ($('input#photo').val().length === 0) {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Hide the element&nbsp; On keyup check the value of the input if length is 0 meaning empty hide the div otherwise show.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$('div.sofdown').hide(); // Using hide()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Or using fadeOut();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$('div.sofdown').fadeOut(1000);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }//Initiate to hide the div if there is no text in input.inputChange();之后初始状态将是hidden这应该添加到JS文件的末尾$('input#photo').keyup(function() {&nbsp;&nbsp; &nbsp; //Call function&nbsp; &nbsp; inputChange();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript