我想建立一個真實或大膽的網站,人們可以在其中玩真話或在線游戲,但我遇到了一些問題。
html代碼
<button id="truth"> t </button>
<div><p id="game"> t for English Truth, d For English Dare, tb For Bangla Truth, db for Bangla Dare</p></div>
這是我的 js 代碼
const t = [
"If you could be invisible, what is the first thing you would do?",
"What is a secret you kept from your parents?",
"What is the most embarrassing music you listen to?",
"What is one thing you wish you could change about yourself?",
"Who is your secret crush?",
];
document.getElementById('truth').addEventListener('click', function(){
const truth = t[Math.floor(Math.random() * t.length)];
const games = document.getElementById('game');
console.log(truth)
games.innerText(truth)
})
但是當我點擊按鈕時,它說Uncaught TypeError: games.innerText is not a function
現在,我能做什么?
uj5u.com熱心網友回復:
它說 games.innerText 不是一個帶引數的函式。正確使用innerText方法是:
games.innerText = truth;
與innerHtml相同
看一看來自 MDN 的 innerText 檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/363222.html
標籤:javascript html 网络
