[每当我单击按钮时,就会调用功能窗口onClick。我希望先调用按钮功能,然后再调用窗口。如何使函数依次调用?
window.onclick = myFunction;
function myFunction() {
document.getElementById("demo").innerHTML = "∠CAD=∠DAE (AD bisects ∠CAE)";
document.getElementById("demo2").innerHTML = "Select one of the statements to continue:";
document.getElementById("button1").className = 'button1';
document.getElementById("button2").className = 'button2';
window.onclick = myFunction2;
function myFunction2() {
document.getElementById("demo4").innerHTML = "Now let’s complete the proof! Select the next statement:";
document.getElementById("button3").className = 'button3';
document.getElementById("button4").className = 'button4';
}
window.onclick = myFunction3;
function myFunction3() {
$("#button3").animate({
// top: $("#demo3").parent().width() / 2,
top: "-250",
left:"+600"
}, 2000);
}
}
$(document).ready(function(){
$("#button1").click(function(){
$("#button1").fadeOut();
$("#button2").fadeOut();
$("#demo2").fadeOut();
$("#demo3").fadeIn();
});
$("#button3").click(function(){
$("#tick").fadeIn();
$("#button4").attr('disabled','disabled');
});
$("#button4").click(function(){
$("#cross").fadeIn();
$("#speech").fadeIn();
});
});
[不介意使用window.onClick
的错误方式,而只是关注主要问题,请使其他按钮不属于window.onClick
。window.onClick
获得所有单击页面的事件,所以为什么不对您的window.onClick
加上条件。
window.onclick = myFunction;
function myFunction(event) {
var btn = event.target.className;
if (btn == "not-part") {
console.log("this will not trigger the other part of the function");
} else {
// Your other codes here
}
}
<button class="part">CLICK ME</button>
<button class="not-part">DON'T CLICK ME</button>