[英]Delay actions in Jquery
我有一个功能,可以处理我网站上订单的结帐。 现在,我还没有添加任何ajax,也没有添加,但是我正在尝试使用javascript和bootstraps模态制作一种“加载屏幕”。 这就是我所拥有的:
Java脚本
function printCheckout() {
// Show the progress Modal
$('#myModal').modal({
keyboard: false,
backdrop: 'static',
});
$('#myModal').modal('show');
// Billing Information
$(".stepText").delay(800).html('Processing Billing Information');
// I want this ^ to delay the process and make it seem longer.
var name = $("input[name='bill_name']").val();
var address = $("input[name='bill_address_1']").val() + $(
"input[name='bill_address_2']").val();
var city = $("input[name='bill_city']").val();
var state = $("input[name='bill_state']").val();
var zip = $("input[name='bill_zip']").val();
var email = $("input[name='bill_email']").val();
var phone = $("input[name='bill_phone']").val();
var billing = 'name=' + name + '&address=' + address + '&city=' + city +
'&state=' + state + '&zip=' + zip + '&email=' + email + '&phone=' +
phone;
// Shipping Informaiton
$(".stepText").delay(800).html('Processing Shipping Information');
var name = $("input[name='ship_name']").val();
var address = $("input[name='ship_address_1']").val() + $(
"input[name='ship_address_2']").val();
var city = $("input[name='ship_city']").val();
var state = $("input[name='ship_state']").val();
var zip = $("input[name='ship_zip']").val();
var email = $("input[name='ship_email']").val();
var phone = $("input[name='ship_phone']").val();
var shipping = 'name=' + name + '&address=' + address + '&city=' + city +
'&state=' + state + '&zip=' + zip + '&email=' + email + '&phone=' +
phone;
// Payment Information
$(".stepText").delay(800).html('Processing Payment Information');
var number = $("input[name='number']").val();
var expiry_month = $("input[name='expiry_month']").val();
var expiry_year = $("input[name='expiry_year']").val();
var cvv = $("input[name='cvv']").val();
var payment = 'number=' + number + '&expiry_month=' + expiry_month +
'&expiry_year=' + expiry_year + '&cvv=' + cvv;
return false;
}
我希望模式根据我们所处的步骤来显示一些如上所示的文本。
Processing Billing Information
Processing Shipping Information
Processing Payment Information
我希望将其延迟,因为现在模式打开后,它已经在最后一步,即上面的付款对帐单上了。
希望我的问题有道理! 谢谢您的帮助。
您应该使用
setTimeout(function(){
// Whatever code to give delay of 3s
},3000);
最简单的方法是使用超时
https://developer.mozilla.org/fr/docs/Web/API/Window.setTimeout
setTimeout(function(){ ... }, delayModal) // delayModal integer in ms
如果您使用的是Bootstrap 3
事件是名称空间,模态的show
事件是show.bs.modal
有关更多详细信息,请参见http://getbootstrap.com/javascript/#js-events
您的代码应如下所示:
$('#myModal').on('show.bs.modal', function (e) {
// your script
})
演示:
http://jsfiddle.net/5960g3xt/1/ <=您应该怎么做
http://jsfiddle.net/5960g3xt/2/ <=我在第二秒上添加了一些延迟,以便您可以看到更改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.