2017-04-07 31 views

回答

1

你什麼時候創建或追加一個元素可以試試這個

$('#btnId').click(function(){ 
$("#divId").append("<p id="test">Test</p>"); 

    setTimeout(function(){ 
     $('#test').remove(); 
    }, 1000); 
    }) 
0

您可以使用此:

<button>Click Me</button> 
<div id="show"></div> 

$(document).ready(function() { 
    $('button').click(function(){ 
     $("#show").append("<p>Test</p>"); 
     $("#show").delay("600").fadeOut("600"); 
    }); 
}); 

你可以根據你改變時間..!

0

$(document).ready(function(){ 
 
    $(".abc").click(function(){ 
 
     $(".inner").append("<p>Test</p>"); 
 
     setTimeout(function(){$('p').remove();}, 1000); 
 
     }); 
 
});
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> 
 
</head> 
 
<body> 
 

 
<div class="inner"> 
 
<input type="button" value="Click me" class="abc"> 
 
</div> 
 
</body> 
 
</html>

0

您可以使用jQuery .append()setTimeout

$('#btnId').click(function(){ 
    $("#divToAppendId").append("<span id="tempDivId">Element</span>"); 

    setTimeout(function(){$('#tempDivId').remove();}, 1000); 
    }) 

這裏1000是在毫秒的單元,其是指1秒。所以1秒後的元素將被刪除。