为了账号安全,请及时绑定邮箱和手机立即绑定

如果未指定自定义字段,我想隐藏 <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 关注
  • 35 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信