Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

php - Output message when button is clicked and then make it automatically disappear after some time

I want to output text once a button is clicked but also have it automatically disappear within a specific time frame. Currently, I have written php code so that the message appears when the button is clicked but I am not sure how to make it automatically disappear within a given time frame. The following is the php code I have:

     <?php if (isset($_SESSION['msg'])): ?>
   <div class="msg">
     <?php

         echo $_SESSION['msg'];
         unset($_SESSION['msg']);
     ?>
   </div>
 <?php endif ?>

$_SESSION['msg] is obtained from another file and its code is shown below:

    if (isset($_POST['submit'])) {
  $_SESSION['msg'] = "Data Entry Added!";
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Best way to achieve this using jQuery.

Include Jquery in your app

Create a message div with style display:none by default.

On button click add on click function to change content of that div with your message you can use ajax request to retrieve that message from PHP.

Once you change content use javascript method to show & hide after interval

$('#messagediv).show().delay(1000).fadeOut();

Refer to this for more details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...