gpt4 book ai didi

javascript - 不知道为什么我总是收到这些奇怪的字符?尝试查看特定用户的推文

转载 作者:行者123 更新时间:2023-12-02 14:51:03 26 4
gpt4 key购买 nike

我想要实现的目标是,当我点击用户时,它只能看到他们的推文。

出于某种原因,当我运行代码时,我不断收到这些奇怪的字符。这是 chrome 开发工具中奇怪字符的照片: enter image description here我指的字符是div class="

之后的字符

我相信这与这一行有关:

var $tweet = $('<div class=“user" data-user="' + tweet.user + '"></div>');

这是我的代码:

  
<script>
$(document).ready(function(){

var globalVar;

var makeTweets = function(){
var $body = $('.tweet-display');
$body.html('');

var index = streams.home.length - 1;
while(index >= 0){
var tweet = streams.home[index];
var $tweet = $('<div class=“user" data-user="' + tweet.user + '"></div>');
$tweet.text('@' + tweet.user + ': ' + tweet.message);
if (globalVar === undefined) {
$tweet.appendTo($body);
} else if(globalVar===tweet.user){
$tweet.appendTo($body);
}
index -= 1;
}
}
makeTweets();
setInterval(function() {
makeTweets();
}, 1000);
});

</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="jquery.js"></script>
<script src="data_generator.js"></script>
</head>
<body>
<div class="navbar">
<div id="navbar-text">
Twittler Project
<!-- <div class="button new-tweet">New Tweet</div>
<div class="button refresh">Refresh</div>
<div class="button ">Button</div> -->
</div>
<div id="twittler-bird">
<a href="http://imgur.com/zuTfb54"><img src="http://i.imgur.com/zuTfb54.png" title="source: imgur.com" style="height:100px;" /></a>
</div>
</div>
<!-- <div class="tweet-inside">test</div> -->
<div class="tweet-container">
<div class="tweet-display">
</div>
</div>
<div class="sidebar-right">
<div class="button tweet-new"></div>
<div class="button"></div>
</div>

为了以防万一,这里有一些与之配对和链接的 JavaScript:

// set up data structures
window.streams = {};
streams.home = [];
streams.users = {};
streams.users.shawndrost = [];
streams.users.sharksforcheap = [];
streams.users.mracus = [];
streams.users.douglascalhoun = [];
window.users = Object.keys(streams.users);

// utility function for adding tweets to our data structures
var addTweet = function(newTweet){
var username = newTweet.user;
streams.users[username].push(newTweet);
streams.home.push(newTweet);
};

// utility function
var randomElement = function(array){
var randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
};

// random tweet generator
var opening = ['just', '', '', '', '', 'ask me how i', 'completely', 'nearly', 'productively', 'efficiently', 'last night i', 'the president', 'that wizard', 'a ninja', 'a seedy old man'];
var verbs = ['drank', 'drunk', 'deployed', 'got', 'developed', 'built', 'invented', 'experienced', 'fought off', 'hardened', 'enjoyed', 'developed', 'consumed', 'debunked', 'drugged', 'doped', 'made', 'wrote', 'saw'];
var objects = ['my', 'your', 'the', 'a', 'my', 'an entire', 'this', 'that', 'the', 'the big', 'a new form of'];
var nouns = ['cat', 'koolaid', 'system', 'city', 'worm', 'cloud', 'potato', 'money', 'way of life', 'belief system', 'security system', 'bad decision', 'future', 'life', 'pony', 'mind'];
var tags = ['#techlife', '#burningman', '#sf', 'but only i know how', 'for real', '#sxsw', '#ballin', '#omg', '#yolo', '#magic', '', '', '', ''];

var randomMessage = function(){
return [randomElement(opening), randomElement(verbs), randomElement(objects), randomElement(nouns), randomElement(tags)].join(' ');
};

// generate random tweets on a random schedule
var generateRandomTweet = function(){
var tweet = {};
tweet.user = randomElement(users);
tweet.message = randomMessage();
tweet.created_at = new Date();
addTweet(tweet);
};

for(var i = 0; i < 10; i++){
generateRandomTweet();
}

var scheduleNextTweet = function(){
generateRandomTweet();
setTimeout(scheduleNextTweet, Math.random() * 1500);
};
scheduleNextTweet();

// utility function for letting students add "write a tweet" functionality
// (note: not used by the rest of this file.)
var writeTweet = function(message){
if(!visitor){
throw new Error('set the global visitor property!');
}
var tweet = {};
tweet.user = visitor;
tweet.message = message;
addTweet(tweet);
};

最佳答案

您在 user 之前的这一行中使用了错误的引号( 而不是 ):

var $tweet = $('<div class=“user" data-user="' + tweet.user + '"></div>');

我认为这可能是问题所在。

关于javascript - 不知道为什么我总是收到这些奇怪的字符?尝试查看特定用户的推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36195699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com