我想在计数器达到特定数字时触发JavaScript,例如10。 我该怎么做?
<button onclick="stepupfunction()"> PRESS ME </button>
<script>
document.addListener('onLoad', function documentLoaded(e) {
document.getElementById("score").value = store.get('putAKeyHere') || 0;
})
function stepupfunction() {
document.getElementById("score").stepUp(1);
store.set('putAKeyHere',document.getElementById("score").value)
}
</script>
答案 0 :(得分:1)
以下内容应该有效:
function stepupfunction() {
var num = document.getElementById("score");
num.stepUp(1);
store.set('putAKeyHere', num.value);
if (num.value >= 10) {
// DO SOMETHING
}
}