我需要一个贝宝按钮来代替一个提交按钮.现在我两者都有,这很奇怪



https://jsfiddle.net/Popo74123/q92jh1p0/474/

这是我的代码。现在贝宝按钮正在提交表单。截至目前,它还没有连接到贝宝。基本上,我想要的是当他们到达表单的最后一步时,下一个按钮变成了贝宝按钮。

<div style="overflow:auto;">
<div style="float:right;">
<button type="button" class="form" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>

js

function nextPrev(n) {
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length) {
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
}
// Otherwise, display the correct tab:
showTab(currentTab);
}

这里是另一个功能,我相信是在哪里我可以修复它

function showTab(n) {
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0) {
document.getElementById("prevBtn").style.display = "none";
} else {
document.getElementById("prevBtn").style.display = "inline";
}
if (n == (x.length - 1)) {
document.getElementById("nextBtn").innerHTML = "Submit";
} else {
document.getElementById("nextBtn").innerHTML = "Next";
}
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
}

我不能编辑if语句吗?其中innerHTML = "submit"to where submit是贝宝按钮吗?我不知道如何引用贝宝按钮。

当一切就绪时,您可以添加一个div或span来包含下一个按钮,您可以像在这段代码中那样替换这个按钮。

<div style="overflow:auto;">
<div style="float:right;">
<button type="button" class="form" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<div class="ToBeFilledWithPaypalBtnLater"> 
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
</div>

function finallyPaypalButton(){
var btn = '<button type="button" id="nextBtn" onclick="PayWithPaypal()">Next</button>'
document.getElementById("nextBtn").innerHTML = btn
/* better approach to create a span or div to include this button to replace 
then replace the code below 
*/ 
// document.getElementById("nextBtnSPAN").innerHTML = btn 
}


function nextPrev(n) {
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) {
finallyPaypalButton() ;
return false;
}
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length) {
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
}
// Otherwise, display the correct tab:
showTab(currentTab);
}

相关内容

最新更新