在网页上添加返回按钮。

huangapple go评论72阅读模式
英文:

adding a back button to the webpage

问题

这是HTML代码的翻译部分:

<button ng-disabled="question.answer === undefined || question.answer == '' || question.answer == {}" ng-click="RC.nextQuestion()" type="button" class="btn btn-default" style="float:right ; margin-top:20px">Next</button>

这是JavaScript代码的翻译部分:

this.next = function(){
    if(self.state == "workerIdSlide"){
        if(self.questionId == null && self.partId == null){
            self.load(function(){
                self.state = self.allStates[++self.slideIndex];
            });
            return;
        }
    }
    if(self.slideIndex + 1 < self.allStates.length){
        self.state = self.allStates[++self.slideIndex];
    }else{
        self.submitResults(self.resultsSubmitted, self.handleError);
    }
};

这是您尝试的JavaScript代码的翻译部分:

this.previous = function(){
    if(self.state == "workerIdSlide"){
        if(self.questionId == null && self.partId == null){
            self.load(function(){
                self.state = self.allStates[--self.slideIndex];
            });
            return;
        }
    };
    this.previousQuestion = function(){
        if(self.questionIndex == 0){
            ++self.questionIndex;
        }else{
            self.previous();
        }
    };
};

请注意,您的JavaScript代码中有一些拼写错误和语法错误,已经在翻译时进行了修复。如果您想要添加一个"Back"(返回)按钮,您需要确保按钮的HTML代码已经添加到相应的页面,并且JavaScript代码能够处理点击该按钮时的逻辑。

英文:

I am designing a website such that a question appears on each page and users can go through the questions by clicking on the "Next" button at the bottom of every page and proceed to the next page. I want to add a back button as well so that they can go the previous pages and change their answers whenever needed.
This is the HTML code for the "Next" button:

&lt;button ng-disabled=&quot;question.answer === undefined || question.answer == &#39;&#39; || question.answer == {}&quot; ng-click=&quot;RC.nextQuestion()&quot; type=&quot;button&quot; class=&quot;btn btn-default&quot; style=&quot;float:right ; margin-top:20px&quot;&gt;Next&lt;/button&gt; 

This is the JavaScript code for the "Next" button:

this.next = function(){
        if(self.state == &quot;workerIdSlide&quot;){
            if(self.questionId == null &amp;&amp; self.partId == null){
                self.load(function(){
                    self.state = self.allStates[++self.slideIndex];
                });
                return;
            }
        }
        if(self.slideIndex + 1 &lt; self.allStates.length){
            self.state = self.allStates[++self.slideIndex];
        }else{
            self.submitResults(self.resultsSubmitted, self.handleError);
        }
    };

This is what I tried as for the JavaScript code:

this.previous = function(){
        if(self.state == &quot;workerIdSlide&quot;){
            if(self.questionId == null &amp;&amp; self.partId == null){
                self.load(function(){
                    self.state = self.allStates[--self.slideIndex];
                });
                return;
            }
        }
    };
    this.previousQuestion = function(){
        if(self.questionIndex == 0{
            ++self.questionIndex;
        else{
            self.previous();
        }
    };

But, it did not work. Can someone tell me how I can add a "Back" button?

答案1

得分: 0

Add:

    this.previousQuestion = function(){
        if(self.questionIndex != 0){
            --self.questionIndex;
        }else{
            if(self.questionIndex + 1 >= self.questions.length){
                self.next();
            }
        }
    };

Remove:

    this.previous = function(){
        if(self.state == "workerIdSlide"){
            if(self.questionId == null && self.partId == null){
                self.load(function(){
                    self.state = self.allStates[--self.slideIndex];
                });
                return;
            }
        }
    };

The complete code:

    this.next = function(){
        if(self.state == "workerIdSlide"){
            if(self.questionId == null && self.partId == null){
                self.load(function(){
                    self.state = self.allStates[++self.slideIndex];
                });
                return;
            }
        }

        if(self.slideIndex + 1 < self.allStates.length){
            self.state = self.allStates[++self.slideIndex];
        }else{
            self.submitResults(self.resultsSubmitted, self.handleError);
        }
    };

    this.nextQuestion = function(){
        if(self.questionIndex + 1 < self.questions.length){
            ++self.questionIndex;
        }else{
            self.next();
        }
    };
    this.previousQuestion = function(){
        if(self.questionIndex != 0){
            --self.questionIndex;
        }else{
            if(self.questionIndex + 1 >= self.questions.length){
                self.next();
            }
        }
    };
英文:

Add:

this.previousQuestion = function(){
            if(self.questionIndex != 0){
                --self.questionIndex;
            }else{
              if(self.questionIndex + 1 &gt;= self.questions.length){
                self.next();
              }
            }
        };

Remove:

this.previous = function(){
        if(self.state == &quot;workerIdSlide&quot;){
            if(self.questionId == null &amp;&amp; self.partId == null){
                self.load(function(){
                    self.state = self.allStates[--self.slideIndex];
                });
                return;
            }
        }
    };

The complete code:

this.next = function(){
            if(self.state == &quot;workerIdSlide&quot;){
                if(self.questionId == null &amp;&amp; self.partId == null){
                    self.load(function(){
                        self.state = self.allStates[++self.slideIndex];
                    });
                    return;
                }
            }

            if(self.slideIndex + 1 &lt; self.allStates.length){
                self.state = self.allStates[++self.slideIndex];
            }else{
                self.submitResults(self.resultsSubmitted, self.handleError);
            }
        };

        this.nextQuestion = function(){
            if(self.questionIndex + 1 &lt; self.questions.length){
                ++self.questionIndex;
            }else{
                self.next();
            }
        };
        this.previousQuestion = function(){
            if(self.questionIndex != 0){
                --self.questionIndex;
            }else{
              if(self.questionIndex + 1 &gt;= self.questions.length){
                self.next();
              }
            }
        };

huangapple
  • 本文由 发表于 2023年1月9日 18:52:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定