English 中文(简体)
如何在拖延后修改案文——
原标题:How to change text after delay - jQuery

我有两条 d,有两条id,有一门 style。

foo_1 具有z-index,因此它高于 foo_2。

<div id="foo_1" class="foo"><p>I m awesome.</p></div>
<div id="foo_2" class="foo"><p>No, I am.</p></div>

我想做的是,有1个 f,有2个 behind。

I did try this;

HTML

<div id="foo_1" class="foo"><p>I m awesome</p></div>
<div id="foo_2" class="foo" style="display: none;"><p>No, I am.</p></div>

jQuery

$(document).ready(function()
{
    setTimeout(function()
    {
        $("#foo_1").fadeOut("slow", function ()
        {
            $("#foo_1").remove();                
            $("#foo_1").html($("#foo_2").text());
            $("#foo_1").show();
        });
     }, 5000);
 });

​ Thanks!

问题回答
setTimeout(function()
    {
        $("#foo_1").fadeOut("slow", function ()
        {
            // remove $("#foo_1").remove(); 
            // line from code, 
            // because, its removing #foo_1 from dom, 
            // so in next strp you can t catch it

            // $("#foo_1").remove();           
            $("#foo_1").html($("#foo_2").text());
            $("#foo_1").show();
        });
     }, 5000);

象你再次做的那样,对我来说,是过不起的。

让我总结一下: 你有两个小区,位于同一个地方,但只有第1号oo,因为它站在上。 现在,你想要掩盖第foo_1号,以揭示第2号。

因此,在排除第foo_1:

setTimeout(function() {
    // Make #foo_2 visible
    $( #foo_2 ).show();

    // Fade out #foo_1
    $( #foo_1 ).fadeOut( slow );
}, 5000);

Just use standard jQuery function with parameter in ms FadeOut(500), FadeIn(500):

$(document).ready( function ()
{
  $( #foo_1 ).fadeOut(1500);
  $( #foo_2 ).text( No, I am! ).fadeIn(1000);
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id= foo_1  style= display:block; > I m awesome </div>
<div id = foo_2  style= display:none; ></div>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签