我正在使用textarea标记获取tweet作为输入,但它在文本区域中显示了我的HTML代码。
--vendor-chunk=true
function showTweets() {
console.log('showtweets called');
tweets = JSON.parse(localStorage.getItem('tweets'));
for (let i = 0; i < tweets.length; i++) {
const para = document.createElement('p');
para.appendChild(document.createTextNode(tweets[i]));
document.querySelector('.showtweets').appendChild(para);
/* showtweets is a class name of div in which I want to print tweets. It's just a div with class name 'showtweets'. */
}
}
function getTweets() {
let tweet = document.querySelector('#tweet').value;
let tweets = [];
if (localStorage.getItem('tweets') === null) {
tweets.push(tweet);
} else {
tweets = JSON.parse(localStorage.getItem('tweets'));
tweets.push(tweet);
}
localStorage.setItem('tweets', JSON.stringify(tweets));
showTweets();
}