这是我在网站上的第二篇文章。在我尝试过的所有其他网站中,这个网站提供了最准确和最有用的信息!
我的按钮有点麻烦,我有一个任务是创建一个收件箱并在每个消息实例中添加一个“回复”和“删除”按钮。
如果有比将 HTML 代码强制写入脚本更好的方法,我确实在徘徊,因为每条消息都是动态生成的。任何帮助和/或建议将不胜感激!(对象是从 JSON 文件调用的)。
$(document).ready(function(){
$.getJSON('public/js/data.json', function(json){
$.each(json.data, function(i, data){
var output = '';
if(data.from.id != '234' && data.from.name != 'Alan Ford'){
$("#inbox").append(
output +=
'<div class="post">'+
'<div class="h1">'+data.from.name+' - '+data.subject+'</div>'+ //this gives the name of the person who sent the message and the subject
'<div class="content">'+data.message_formatted+'</div>'+ //The content of the message
//buttons should be squeezed left of the date
//this gives the date of the message sent
'<div class="time">'+data.date_sent_formatted.formatted+'</div>'+
'</div>'
);
}});
});
});
var date_sent=convertToDateTime();
function delete_message(id){
console.log('Delete message with id: '+id);
}
function reply_message(id, sender){
console.log('Message id: '+id);
console.log('Reply to: '+sender);
}