有许多类似的问题,但似乎没有一个能帮助到我。
我正在使用Javascript和html开发一个三步流程。
在前两个步骤中,我有2个表单,每个表单都有一个下一步/上一步按钮。我需要能够从第二步返回第一步,并仍然保留第一步的表单数据。我对javascript还很陌生,任何帮助都将不胜感激。我不确定如何保存表单数据,然后在用户从第二步返回时插入它。
编辑: 我决定使用JS来隐藏/显示表单,请问为什么我的变量永远无法达到currentStep == 3; 当回退时会出现问题,因为currentStep值停留在2处。
var currentStep = 1;
function nextStep() {
if (currentStep ===1){
$("#petmain1").hide();
$("#petmain2").show();
$("#addproduct").show();
$("#firstimage").hide();
$("#secondimage").show();
currentStep = 2;
console.log("Current step is " + currentStep);
}else if(currentStep ===2){
$("#petmain2").hide();
$("#addproduct").hide();
$("#secondimage").hide();
$("#petmain3").show();
$("#thirdimage").show();
$("#firstimage").hide();
currentStep === 3;
console.log("Current step is " + currentStep);
}
}
function prevStep() {
if (currentStep ===2){
$("#petmain1").show();
$("#petmain2").hide();
$("#addproduct").hide();
$("#firstimage").show();
$("#secondimage").hide();
currentStep = 1;
console.log("Current step is " + currentStep);
}else if(currentStep === 3){
$("#petmain3").hide();
$("#thirdimage").hide();
$("#secondimage").show();
$("#petmain2").show();
$("#addproduct").show();
currentStep === 2;
console.log("Current step is " + currentStep);
}
}
display: none
隐藏表单。 - jcubic