javascript - Jquery 中的延迟操作

标签 javascript jquery ajax twitter-bootstrap

我有一个函数可以在我的网站上处理订单的结帐。现在我还没有添加任何 ajax 之类的东西,但我正在尝试使用 javascript 和 bootstraps 模式制作一种“加载屏幕”。这就是我所拥有的:

Javascript

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);

关于javascript - Jquery 中的延迟操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28519123/

相关文章:

jquery - Struts 2 jQuery 插件项目中的 js 文件中将添加 "_=13 digits"

javascript - Express:从 Jade 文件中找不到 $

javascript - 将 html.beginform 内的 Dropdown 值传递给 ajax 操作调用

c# - 如何在asp.net2.0 中更改alterbox 和confirm box 按钮和图标?

javascript - 更改文本框输入的背景颜色在为空时不起作用

javascript - 创建与 JavaScript 一起使用的数据库

javascript - ajax post to file 函数什么都不做

javascript - 如何使用 jQuery/Ajax 执行 MySQL 查询

php - HTML5 : AJAX file upload with progress bar

javascript - 滚动后再次停止加载 iframe 吗?