ホームページに ID 通知を含む div があります。ページが初めてロードされたときに div をロードしたくないので、1 分後にロードするようにします。javascriptまたはjqueryで私がやりたいことをする方法はありますか?
2442 次
4 に答える
3
div を実際に DOM に追加する方法がわかりませんが、setTimeout を使用して 1 分間遅延させることができます。ドキュメントから:
Calls a function or executes a code snippet after specified delay.
だから、このようなもの:
function appendDiv() {
... append code here...
}
timeoutID = window.setTimeout(appendDiv, 60000);
于 2013-03-27T19:28:04.570 に答える
2
確かに:)私の例ではjQueryを使用しています:
<div style="display:none" id="notifications"></div>
<script type="text/javascript">
$(document).ready(function() {
setTimeout(function() {
$.get('/notifications.php', function(result) {
// build your notifications here
// ...
$('#notifications').show();
}, 'json');
}, 60000);
});
</script>
于 2013-03-27T19:28:44.057 に答える
0
jQuery のload
関数を使用する:
setTimeout(function() {
$('#myDiv').load('divcontents.html');
}, 60 * 1000);
divcontents.html
サーバー上で動的に生成できます。
于 2013-03-27T19:40:30.370 に答える
0
最初の 1 分間、通知が DOM にまったくない場合は、次のコードを使用します。
$(document).ready(function(){
setTimeout( function(){
$("<div>")
.html( "your notification message/markup" )
.attr({ id : 'notification', ... })
.appendTo( "body" /* or any other DOM element */ );
}, 60*1000);
})
于 2013-03-27T19:36:07.643 に答える