单击事件在 html DOM innerTEXT 中不起作用
Click event is not working in html DOM innerTEXT
我想制作一个真心话大冒险网站,供人们在线玩真心话大冒险游戏,但我遇到了一些问题。
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
现在,我能做什么?
它说 games.innerText 不是一个带参数的函数。 innerText方法的正确用法是:
games.innerText = truth;
与 innerHtml 相同
我想制作一个真心话大冒险网站,供人们在线玩真心话大冒险游戏,但我遇到了一些问题。
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
现在,我能做什么?
它说 games.innerText 不是一个带参数的函数。 innerText方法的正确用法是:
games.innerText = truth;
与 innerHtml 相同