2014-09-24 132 views
0

在我的表单上,您必须选择一个项目才能显示表单。我遇到的问题是提交时隐藏了表单。我该如何纠正?表单隐藏提交

这是我的脚本:

<script> 
    $(document).ready(function() { 
    $(".orderForm").hide(); 


    $(".choice").each(function() { 


     $(this).click(function() { 
      $(".orderForm").show(); 


     }); 

    }); 

}); 
</script> 

下面是HTML的一部分:

<form method="post" class="form-horizontal"> 
     <div class="choiceContainer"> 
      <@choicesSection><@choice id="2098885" class="choice"> 
     <label> 
      <div align="left"> 
       <h3 class="choiceName"> 
        <@choiceSelectionRadioButton /> 
        <@choiceName>148PKI</@choiceName> 
       </h3> 
       <div class="orderForm"> 
     </div> 
     </div></div> 
<div class="btn" align="center"><@selectedPaymentOptionSubmitButton label="Continue"  
class="continue"/></div> 

我更新了剧本太。

+1

我要去猜测,透过重新加载页面。你在'$(document).ready'中有一个'.hide'。 – 2014-09-25 16:56:42

+0

你也可以使用submit()来处理提交。 http://api.jquery.com/submit/ – 2014-09-25 16:57:36

+0

是的,它重新加载页面。我该如何解决这个问题? – Military911 2014-09-25 16:58:31

回答

0

使用sessionStorage(或适当的polyfill脚本)跨页加载持久化变量。 (注sessionStorage的序列数据,从而获得价值将不再是true但是字符串"true"时)

$(document).ready(function() { 
    if(!sessionStorage.formSubmitted) 
     $(".orderForm").hide(); 

    //Reset it for possibly another form submission 
    sessionStorage.removeItem('formSubmitted'); 


    $(".choice").each(function() { 


     $(this).click(function() { 
      $(".orderForm").show(); 
     }); 

    }); 

    $("form.form-horizontal").submit(function(){ 
     sessionStorage.formSubmitted = true; 
    }); 

}); 
+0

谢谢。现在我明白你是如何为表单做这件事的,信用卡部分应该是同样的方式,因为两者都与提交按钮绑定在一起? – Military911 2014-09-25 20:06:01

+0

@ Military911很难说,因为它没有包含在你的问题中,但同样的方法很可能也适用于你的问题。 – 2014-09-25 20:08:17

+0

我猜没有办法私下发信息了,是吧? – Military911 2014-09-25 20:16:35