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

如何使用php触发元素隐藏

如何使用php触发元素隐藏

PHP
慕的地8271018 2021-11-26 19:57:05
我有以下 php 代码回显警报。echo '<div class="alert alert-warning alert-dismissible" id = "noOperator" role="alert" >      <strong>Not certified! </strong>'.$checkBoxValue.' is not certified to use '.$needleType.'      <button type="button" class="close" data-dismiss="alert" aria-label="Close">      <span aria-hidden="true">&times;</span></button>      </div>';但是我想在它显示后关闭这个警报。因此,我再次给出了以下作为回声。echo ' <script>      $("#noOperator").fadeTo(2000, 500).slideUp(500, function(){           $("#noOperator").slideUp(500);      });       </script>';但它不起作用有谁知道为什么?
查看完整描述

1 回答

?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

为什么不使用 JQuery 而不使用 PHP 回显代码。并检测元素是否可见以触发隐藏功能。或者只是使用警报框的关闭按钮。


setTimeout(function() {

  if ($("#noOperator").is(":visible")) {

    //$('#noOperator').hide();

     $("#noOperator").animate({

        'margin-top' : "-50%",

        'opacity' : '0',

        'visibility' : 'hide'

      },1000);

   

    console.log("hiding now")

  }

  

}, 1000); // hide the element if visible after 1 second



//or just use the button on the alert box

//if you want it just uncomment below


//$('.close').click(function(){

//    $('#noOperator').hide();

//});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

<div class="alert alert-warning alert-dismissible" id="noOperator" role="alert">

  <strong>Not certified! </strong>

  <button type="button" class="close" data-dismiss="alert" aria-label="Close">

      <span aria-hidden="true">&times;</span></button>

</div>

如果您将其更改为:


echo '<script>

         setTimeout(function() {

            $("#noOperator").fadeTo(2000, 500).slideUp(500, function(){

              $("#noOperator").slideUp(500);

            });

         }, 3000);

      </script>';


查看完整回答
反对 回复 2021-11-26
  • 1 回答
  • 0 关注
  • 195 浏览

添加回答

举报

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