如何使用php触发元素隐藏

我有以下 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>';

但它不起作用


有谁知道为什么?


慕的地8271018
浏览 196回答 1
1回答

繁星点点滴滴

为什么不使用 JQuery 而不使用 PHP 回显代码。并检测元素是否可见以触发隐藏功能。或者只是使用警报框的关闭按钮。setTimeout(function() {&nbsp; if ($("#noOperator").is(":visible")) {&nbsp; &nbsp; //$('#noOperator').hide();&nbsp; &nbsp; &nbsp;$("#noOperator").animate({&nbsp; &nbsp; &nbsp; &nbsp; 'margin-top' : "-50%",&nbsp; &nbsp; &nbsp; &nbsp; 'opacity' : '0',&nbsp; &nbsp; &nbsp; &nbsp; 'visibility' : 'hide'&nbsp; &nbsp; &nbsp; },1000);&nbsp; &nbsp;&nbsp; &nbsp; console.log("hiding now")&nbsp; }&nbsp;&nbsp;}, 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(){//&nbsp; &nbsp; $('#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">&nbsp; <strong>Not certified! </strong>&nbsp; <button type="button" class="close" data-dismiss="alert" aria-label="Close">&nbsp; &nbsp; &nbsp; <span aria-hidden="true">&times;</span></button></div>如果您将其更改为:echo '<script>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setTimeout(function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#noOperator").fadeTo(2000, 500).slideUp(500, function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#noOperator").slideUp(500);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}, 3000);&nbsp; &nbsp; &nbsp; </script>';
打开App,查看更多内容
随时随地看视频慕课网APP