简体   繁体   English

如何在 html 中添加条件按钮 function?

[英]How do i add conditional button function in html?

Im a newbie trying to make a progressive website.我是一个试图制作一个渐进式网站的新手。 I want the users to go through 7 tests on each level and only if they complete 4/7 tests successfully will they be allowed to progress to the next level (webpage).我希望用户通过每个级别的 7 次测试达到 go,只有成功完成 4/7 测试,他们才能进入下一个级别(网页)。 How do i add this condition check of 4/7 successful completions to my button which will take the user to the next page?如何将 4/7 成功完成的条件检查添加到我的按钮中,这会将用户带到下一页?

Set the button's display to none in css在 css 中将按钮的显示设置为无

#buttonToNextPage{
    display : none;
}

Using a variable in javascript to keep track of the number of tests your user has answered.使用 javascript 中的变量来跟踪用户已回答的测试数量。 The variable can start from 1 and go upto 4变量可以从 1 开始,go 最多 4

var testAnswered = 1;

Every time the user answers a new test, you can increment the number by 1 by triggering a function.每次用户回答新测试时,您可以通过触发 function 将数字加 1。 After incrementing, within the function u should check if the value has reached 4.If yes, you display the button using javascript.递增后,在 function 中,您应检查该值是否已达到 4。如果是,则使用 javascript 显示按钮。 The function must look something like this: function 必须如下所示:

function newTestAnswered(){
    testAnswered = testAnswered + 1;
    if(testAnswered == 4){
        document.querySelector('#buttonToNextPage').style.display = block;
    }
}

Hope this helped☺希望这有帮助☺

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM