我曾经玩过addEventListener()
,但似乎无法弄清楚它是如何工作的。我想尝试这样做,以便事件侦听器识别总金额何时达到某个特定点,然后触发功能mow()
。
window.addEventListener(); //???
function mowEm(){
var moreMow = setInterval('mow()', 1000);
}
function mow(){
window.money = document.getElementById('tot');
money.innerHTML = Number(money.innerHTML) + 2;
}
<div class="tot" id="tot">
0
</div>
<br><br><br>
<div class="element">
<input class=button type=button value="Hire employee" onclick='mowEm()'>
Click to mow someone's lawn.
<input class=button type=button value="MOW" onclick='mow()'>
</div>
有人对我如何进行这项工作有任何想法吗?
答案 0 :(得分:2)
听起来您只需要听钱才能达到一定水平,然后再执行其他操作即可。您可以通过在每次上升时检查该值来做到这一点:
Textview
function mow() {
money.innerHTML = Number(money.innerHTML) + 2;
if (money.innerHTML === '8') {
alert('Amount of 8 reached, fire some function and do something...');
}
}
//window.addEventListener(); //???
var money = document.getElementById('tot');
function mowEm() {
var moreMow = setInterval('mow()', 1000);
}
function mow() {
money.innerHTML = Number(money.innerHTML) + 2;
if (money.innerHTML === '8') {
alert('Amount of 8 reached, fire some function and do something...');
}
}
.hidden {
display: none;
}
.show {
display: block;
}
h1 {
font-size:40px;
text-align:center;
color:#032441;
}
.tot {
font-size:90px;
text-align:center;
color:#032441;
}
.element {
font-size:20px;
text-align:center;
color:#032441;
}
.button {
background-color:;
color:#032441;
cursor:pointer;
}