我有对象,我试图比较它们的值,并使一个函数发生,如果一个值大于另一个。但是我的代码似乎是错误的,因为即使值大于另一个,它仍然控制台日志"false"而不是真的。我甚至控制台记录了这个值,以检查它是否更大。这是我的代码。
var clicks1 = 0;
function onClick() {
clicks1 += 1;
document.getElementById("clicks1").innerHTML = clicks1;
document.getElementById("clicks1").value = clicks1;
var clicks2 = 0;
function onClick() {
clicks2 += 1;
document.getElementById("clicks2").innerHTML = clicks2;
document.getElementById("clicks2").value = clicks2;
playbutton.onclick = function () {
const click1var = document.getElementById("clicks1").value
const click2var = document.getElementById("clicks2").value
console.log(click1var) //Console shows 3
console.log(click2var) //Console shows 1
if (click1var < click2var) {
console.log('true')
} else {
console.log('false') //Console shows false.
}
}
click1var = 3
if (click1var
则它将转到else