我想在用户单击它们后更改html页面上显示的金额。有2个按钮,单击每个按钮后,应将它们定向到新的html,并且其数量应相应更改。我知道这并不是真正的方法,但是我不确定我还能怎么做。目前,我只能附加所有金额。
elif (actual_email) == (email): print("Email is valid")
<button onclick="myFunction1()" type="submit" id="one">BUY</button>
<button onclick="myFunction2()" type="submit" id="two">BUY</button>
function myFunction1() {
window.location='pay.html';
};
function myFunction2() {
window.location = 'pay.html';
};
<span class="title" id="total"></span>
<span class="title" id="total2"></span>
想要获得以下结果:通过单击第一个按钮,将用户重定向到pay.html并显示$ 100。通过单击第二个按钮,重定向到相同的html(pay.html),显示$ 300。请多多帮助。
答案 0 :(得分:0)
您可以给id设置跨度,然后将文本设置为300或100
function pot(t, pr = 0){ // target and previous result
var d = Math.abs(t - pr), // difference
n = Math.round(Math.log(d)/Math.log(2)), // the n figure
cr = t > pr ? pr + 2**n // current result
: pr - 2**n;
return t > cr ? `2^${n} + ` + pot(t, cr) // compose the string result
: t < cr ? `2^${n} - ` + pot(t, cr)
: `2^${n}`;
}
console.log(pot(29));
console.log(pot(1453));
console.log(pot(8565368));
答案 1 :(得分:0)
使用参数向GET
发送pay.html
请求:
window.location='pay.html?amount=100';
通过JS访问参数
var url= new URL(document.location).searchParams;
var amount=url.get("amount");
var totalamt = '$'+ amount;
$('#total').html("<span style='float:right'>" + "Total:" + totalamt + "</span>");
yourhtml.html :
<button onclick="myFunction1()" type="submit" id="one">BUY</button>
<button onclick="myFunction2()" type="submit" id="two">BUY</button>
function myFunction1() {
window.location='pay.html?amount=100';
};
function myFunction2() {
window.location = 'pay.html?amount=300';
};
pay.html :
<span class="title" id="total"></span>
var url = new URL(document.location).searchParams;//Getting search params
var amount = url.get("amount"); //Getting value of amount from parameters
var totalamt = '$'+ amount;
$('#total').html("<span style='float:right'>" + "Total:" + totalamt + "</span>");
这也可以在没有Real应用的情况下使用。