在网页上添加返回按钮。

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

adding a back button to the webpage

问题

这是HTML代码的翻译部分:

  1. <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代码的翻译部分:

  1. this.next = function(){
  2. if(self.state == "workerIdSlide"){
  3. if(self.questionId == null && self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[++self.slideIndex];
  6. });
  7. return;
  8. }
  9. }
  10. if(self.slideIndex + 1 < self.allStates.length){
  11. self.state = self.allStates[++self.slideIndex];
  12. }else{
  13. self.submitResults(self.resultsSubmitted, self.handleError);
  14. }
  15. };

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

  1. this.previous = function(){
  2. if(self.state == "workerIdSlide"){
  3. if(self.questionId == null && self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[--self.slideIndex];
  6. });
  7. return;
  8. }
  9. };
  10. this.previousQuestion = function(){
  11. if(self.questionIndex == 0){
  12. ++self.questionIndex;
  13. }else{
  14. self.previous();
  15. }
  16. };
  17. };

请注意,您的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:

  1. &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:

  1. this.next = function(){
  2. if(self.state == &quot;workerIdSlide&quot;){
  3. if(self.questionId == null &amp;&amp; self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[++self.slideIndex];
  6. });
  7. return;
  8. }
  9. }
  10. if(self.slideIndex + 1 &lt; self.allStates.length){
  11. self.state = self.allStates[++self.slideIndex];
  12. }else{
  13. self.submitResults(self.resultsSubmitted, self.handleError);
  14. }
  15. };

This is what I tried as for the JavaScript code:

  1. this.previous = function(){
  2. if(self.state == &quot;workerIdSlide&quot;){
  3. if(self.questionId == null &amp;&amp; self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[--self.slideIndex];
  6. });
  7. return;
  8. }
  9. }
  10. };
  11. this.previousQuestion = function(){
  12. if(self.questionIndex == 0{
  13. ++self.questionIndex;
  14. else{
  15. self.previous();
  16. }
  17. };

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

答案1

得分: 0

Add:

  1. this.previousQuestion = function(){
  2. if(self.questionIndex != 0){
  3. --self.questionIndex;
  4. }else{
  5. if(self.questionIndex + 1 >= self.questions.length){
  6. self.next();
  7. }
  8. }
  9. };

Remove:

  1. this.previous = function(){
  2. if(self.state == "workerIdSlide"){
  3. if(self.questionId == null && self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[--self.slideIndex];
  6. });
  7. return;
  8. }
  9. }
  10. };

The complete code:

  1. this.next = function(){
  2. if(self.state == "workerIdSlide"){
  3. if(self.questionId == null && self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[++self.slideIndex];
  6. });
  7. return;
  8. }
  9. }
  10. if(self.slideIndex + 1 < self.allStates.length){
  11. self.state = self.allStates[++self.slideIndex];
  12. }else{
  13. self.submitResults(self.resultsSubmitted, self.handleError);
  14. }
  15. };
  16. this.nextQuestion = function(){
  17. if(self.questionIndex + 1 < self.questions.length){
  18. ++self.questionIndex;
  19. }else{
  20. self.next();
  21. }
  22. };
  23. this.previousQuestion = function(){
  24. if(self.questionIndex != 0){
  25. --self.questionIndex;
  26. }else{
  27. if(self.questionIndex + 1 >= self.questions.length){
  28. self.next();
  29. }
  30. }
  31. };
英文:

Add:

  1. this.previousQuestion = function(){
  2. if(self.questionIndex != 0){
  3. --self.questionIndex;
  4. }else{
  5. if(self.questionIndex + 1 &gt;= self.questions.length){
  6. self.next();
  7. }
  8. }
  9. };

Remove:

  1. this.previous = function(){
  2. if(self.state == &quot;workerIdSlide&quot;){
  3. if(self.questionId == null &amp;&amp; self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[--self.slideIndex];
  6. });
  7. return;
  8. }
  9. }
  10. };

The complete code:

  1. this.next = function(){
  2. if(self.state == &quot;workerIdSlide&quot;){
  3. if(self.questionId == null &amp;&amp; self.partId == null){
  4. self.load(function(){
  5. self.state = self.allStates[++self.slideIndex];
  6. });
  7. return;
  8. }
  9. }
  10. if(self.slideIndex + 1 &lt; self.allStates.length){
  11. self.state = self.allStates[++self.slideIndex];
  12. }else{
  13. self.submitResults(self.resultsSubmitted, self.handleError);
  14. }
  15. };
  16. this.nextQuestion = function(){
  17. if(self.questionIndex + 1 &lt; self.questions.length){
  18. ++self.questionIndex;
  19. }else{
  20. self.next();
  21. }
  22. };
  23. this.previousQuestion = function(){
  24. if(self.questionIndex != 0){
  25. --self.questionIndex;
  26. }else{
  27. if(self.questionIndex + 1 &gt;= self.questions.length){
  28. self.next();
  29. }
  30. }
  31. };

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:

确定