So as an assignment I need to create a barebones twitter clone.
(因此,作为一项任务,我需要创建一个准系统的Twitter克隆。)
I was given a script that creates random tweets from four users and to display them I'm simply using an interval.(我得到了一个脚本,该脚本可以从四个用户创建随机推文,并且要显示它们,我只是在使用一个间隔。)
My issue is that one of the condition requires that if the user clicks on one of the usernames, the website should show that users tweet history.(我的问题是,其中一种条件要求,如果用户单击用户名之一,则网站应显示用户的推文历史记录。)
The tweets are all stored inside the generator file.(这些推文都存储在生成器文件中。)
I have literally been trying for over a day to get a dynamic click script to run.(实际上,我已经尝试了一天多的时间来运行动态点击脚本。)
I every time a tweet gets appended to the website it has a class of the users name.(每当我在网站上附加一条推文时,都会使用一类用户名。)
The closest I have gotten in terms of logic was to put an onclick=functionName(userclass) inside the anchor of my username.(就逻辑而言,我得到的最接近的结果是将onclick = functionName(userclass)放在我的用户名的锚点内。)
But it is out of scope.(但这超出了范围。)
I'm pretty new at html/jquery.(我是html / jquery的新手。)
In fact it is my first week so I have been reading up for hours and you all know how it is when you start learning this stuff.(实际上,这是我的第一个星期,所以我已经阅读了几个小时,并且大家都知道当您开始学习这些东西时情况如何。)
The more you read, the more questions you have.(您阅读的内容越多,所提出的问题就越多。)
Hope somebody can shine some light(希望有人可以发光)
Here's the code:
(这是代码:)
<!DOCTYPE html> <html> <head>
<title>TWIDDLER</title>
<link rel="stylesheet" href="style.css">
<script src="jquery.js"></script>
<script src="data_generator.js"></script>
<script src="history.js"></script> </head>
<body>
<img class="bird" src="icon.png">
<h1>
<span class='title' id="top">TWIDDLER (def not Twitter)</span>
</h1>
<script>
$(document).ready(function(){
var $body = $('.tweets');
var index = 0;
setInterval(function(){
var tweet = streams.home[index];
var $tweet = $('<div></div>');
var hypername = tweet.user;
var $username = $("<a onclick='gethistory("+hypername+")' href='#top' class='"+hypername+"'><span></span></a>");
var $endline = $('<br>');
console.log($username);
var time = tweet.created_at.toLocaleTimeString();
$tweet.text(tweet.message + ' | ' + tweet.created_at.toLocaleTimeString());
$username.text('@' + tweet.user + ': ');
$username.appendTo($body)
$tweet.appendTo($body);
// console.log($tweet);
// var testname = $('<h6></h6>').text('***'+hypername+'***').appendTo($body);
$endline.appendTo($body);
index += 1;
}, 2000);
var gethistory = function(name) {
console.log("I clicked it");
for (var i = 0; i < streams.users[name].length; i++) {
var tweethist = streams.users[name][i];
var $tweethist = $('<div></div>');
var $endline = $('<br>');
$tweethist.text(tweet.message + ' | ' + tweet.created_at.toLocaleTimeString());
$tweethist.appendTo('#history');
$endline.appendTo('#history');
}
};
});
</script>
<h3>
<section class="row">
<div class="column1 tweets left"><h2>Tweeds</h2></div>
<div class="column2 right" id="history"></div>
</section>
</h3>
<!-- <section>
<audio controls autoplay src="song.mp3"></audio>
</section> -->
</body>
</html>
ask by Imsuchacoder translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…