我编写了一个 jquery 脚本,它会自动检测用户输入的号码。如果用户输入了 2,4,6,8,10 - 他们将自动弹出一个确认框,说明有报价。
如果他们单击“是”,他们将被重定向。但是,如果他们单击“取消”,它会重新聚焦在文本框上,并且再次出现确认框。
无论如何我可以做到,所以如果用户点击取消,焦点不在文本框上,所以不会出现确认框循环。
HTML
<input type="text" class="Quantity" id="Quantity9438851" name="Quantity" value="1" style="width:30px">
查询
$("#Quantity9438851").bind("change paste keyup", function() {
if($(this).val() == 2){
var didConfirm = confirm("There is currently an offer for 2 polo shirt for £25. Click YES to recieve discount.");
if (didConfirm == true) {
window.location.href = "http://blahblah.com/&Quantity=10";
}
}else if($(this).val() == 4){
var didConfirm = confirm("There is currently an offer for 4 polo shirt for £50. Click YES to recieve discount.");
if (didConfirm == true) {
window.location.href = "http://google.com/Registration/blah";
}
}else if($(this).val() == 6){
var didConfirm = confirm("There is currently an offer for 6 polo shirt for £75. Click YES to recieve discount.");
if (didConfirm == true) {
window.location.href = "http://google.com/Registration/blah";
}
}else if($(this).val() == 8){
var didConfirm = confirm("There is currently an offer for 8 polo shirt for £100. Click YES to recieve discount.");
if (didConfirm == true) {
window.location.href = "http://google.com/Registration/blah";
}
}else if($(this).val() == 10){
var didConfirm = confirm("There is currently an offer for 10 polo shirt for £100. Click YES to recieve discount.");
if (didConfirm == true) {
window.location.href = "http://google.com/Registration/blah";
}
}
});