2016-09-28 99 views
0

我为我的网站提供了一个页面结帐,因此我决定将它分离为5个部分,并使用javascript一次显示一个或两个显示。当页面重新载入时Javascript更改重置

看到下面的代码:

<fieldset id="vm-fieldset-pricelist" class="vm-fieldset-pricelist"> ... </fieldset> 

    <div id="coupon-section" class="coupon-section display-none"> ... </div> 

    <fieldset id="shipment-section" class="shipment-section display-none"> ... </fieldset> 

    <div id="edit-account-section" class="billto-shipto display-none"> ... </div> 

    <div id="part-five" class="display-none"> ... </div> 


    <?php 
        $user = JFactory::getUser(); 
        if ($user->guest) { 
         $usercheckin = '_notloggedin'; 
        } else { 
         $usercheckin = '_loggedin'; 
        } 
      ?> 

    <button type="button" id="one-to-two<?php echo $usercheckin ?>" class="sabz-button pull-right" onclick="cartButtonHandler(this.id); return false;"><?php echo vmText::_('COM_VIRTUEMART_CHECKOUT_TITLE')?> </button> 

<script> 

window.cartButtonHandler = function(button_id) { 
    switch(button_id) { 
    case 'one-to-two_notloggedin': 
     document.getElementById("vm-fieldset-pricelist").className = "display-none"; 
     document.getElementById("com-form-login").className = ""; 
     document.getElementById(button_id).innerHTML = "ثبت اطلاعات و ادامه خرید"; 
     document.getElementById(button_id).className = "abi-button pull-right"; 
     document.getElementById(button_id).id = 'two-to-three'; 
     break; 
    case 'one-to-two_loggedin': 
     document.getElementById("vm-fieldset-pricelist").className = "display-none"; 
     document.getElementById("edit-account-section").className = "billto-shipto display-none"; 
     document.getElementById("shipment-section").className = "shipment-section"; 
     document.getElementById(button_id).innerHTML = "ثبت اطلاعات و ادامه خرید"; 
     document.getElementById(button_id).className = "abi-button pull-right"; 
     document.getElementById(button_id).id = 'two-to-three'; 
     break; 
    case 'two-to-three': 
     document.getElementById("edit-account-section").className = "display-none"; 
     document.getElementById("shipment-section").className = "display-none"; 
     document.getElementById("coupon-section").className = "coupon-section"; 
     document.getElementById(button_id).innerHTML = "بازبینی و تایید سفارش"; 
     document.getElementById(button_id).id = 'three-to-four'; 
     break; 
    case 'three-to-four': 
     document.getElementById("part-chahar").className = ""; 
     document.getElementById("vm-fieldset-pricelist").className = "vm-fieldset-pricelist"; 
     document.getElementById("edit-account-section").className = "billto-shipto display-none"; 
     document.getElementById("shipment-section").className = "shipment-section"; 
     document.getElementById("coupon-section").className = "coupon-section"; 
     document.getElementById("handlerbutton-section").className = "display-none"; 
     document.getElementById(button_id).id = 'four-to-five'; 
     break; 
    case 'four-to-five': 
     alert(button_id); 
     break; 
} 
} 

    </script> 

首先,我不知道的JavaScript,有没有更好的办法在JavaScript或jQuery的还是要做到这一点...?

我的问题:当用户在“优惠券区”输入优惠券代码并点击提交按钮时,介意优惠券提交按钮与NEXT STEP按钮不同,页面重新加载并弹出第一步。 或当用户选中复选框或任何其他交互时,页面重新加载并弹出第一步。

如何保存javascript更改并将它们重新载入页面重新加载,以便用户可以在与表单交互后保留在同一步骤中? 我想这可能是使用cookie或其他方法解决的,但我不知道该怎么做。

+0

本地存储或会话存储可以帮助你 –

+0

如果你不想重新加载页面停止提交按钮默认动作 –

+0

你不怎么编码的JavaScript? – Beginner

回答

0

1.通过Jquery轻松实现html(DOM)操作和选择。

  • 经过文档sessionStorage的,(设置和获取的项目在broswer上重装 会议)

  • 了解JSON,创建一个JSON结构来记录进度,并进行功能基于该JSON加载部(使一切由数据驱动) 例如:

    [

    { sectionName: “SECTION1”, 亲格雷斯: “开始” }, { sectionName: “第2节”, 进步: “不完整” },
    ]

  • 希望这有助于

    相关问题