我的代码允许在耗时的同时弹出alert
对话框。
如何在 HTML 而不是 JavaScript 对话框中做同样的事情?
我必须用与 AJAX 相关的东西来做吗?
有人可以给我举个例子吗?
jQuery(document).ready(function () {
var comments = [{'time':'5','message':'hello! 5 secs has past'},{'time':'10','message':'hello! 10 secs has past'},{'time':'30','message':'hello! 30 secs has past'}];
$('#video').on('timeupdate',function(e){
showComments(this.currentTime);
});
function showComments(time){
var comments = findComments(time);
$.each(comments,function(i,comment){
alert(comment.message);
});
}
function findComments(time){
return $.grep(comments, function(item){
return item.time == time.toFixed();
});
}
});
HTML
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Show sequential messages in HTML</h1>
<p>
**Messages appears here instead of dialog**
</p>
</body>
最佳答案
在您的 showComments
函数中,替换这一行:
alert(comment.message);
进入这些:
var messages = $('p').text();
$('p').text(messages + comment.message + "\n");
// Show for 5 seconds, then hide the `p` element.
$('p').show().delay(5000).fadeOut();
这样,它将用评论消息填充段落。
关于javascript - 我怎样才能做同样的事情,但在 HTML 而不是 JavaScript 对话框中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18347841/