因此,我正在尝试对54321方法进行编码以消除焦虑,但是该方法适用于第一步,这意味着一个按钮消失了,并且文本发生了变化,但是此后该按钮按原样应该一个一个地消失了,但是文本不会改变。
首先,当我在html文件中有一个onclick事件链接到js文件中的函数时,该方法起作用。现在,我想删除onclick事件,并在js文件中将其替换为'click .thebtn'(event, instance) {}
,但该方法不再起作用。
方法应该像这样继续下去。单击五个按钮后,一个消失,文本更改,然后单击四个按钮,一个消失,文本更改,依此类推,直到没有按钮。
<div class="container">
<div id= "step1">Identify 5 things you see</div>
<button class= "thebtn" id="button1">Button1</button>
<button class= "thebtn" id="button2">Button2</button>
<button class= "thebtn" id="button3">Button3</button>
<button class= "thebtn" id="button4">Button4</button>
<button class= "thebtn" id="button5">Button5</button>
</div>
<script>
Template.theMethod.events({
'click .thebtn'(event, instance) {
compteur ++;
event.preventDefault();
event.currentTarget.setAttribute('class', 'thebtn2');
// // Update state on button click
answered[event.currentTarget.id] = true;
var allTrue = Object.keys(answered).every(function(key){ return answered[key] });
if (allTrue) {
// // Remove a button and reset state
document.getElementById("button" + numberOfButtons).style.display = "none";
if (compteur == 5) {
document.getElementById("step1").innerHTML = "Identify 4 things you see";
//document.getElementsByClassName("thebtn2").setAttribute('class', 'thebtn');
} else if (compteur == 9){
document.getElementById("step1").innerHTML = "Identify 3 things you see";
} else if (compteur ==9){
document.getElementById("step1").innerHTML = "Identify 2 things you see";
} else if (compteur ==15){
document.getElementById("step1").innerHTML = "Identify 1 things you see";
}
}
}
});
</script>