英文:
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:
<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>
This is the JavaScript code for the "Next" button:
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 is what I tried as for the JavaScript code:
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();
}
};
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 >= 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();
}
}
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论