Javascript 表格在提交时隐藏
在我的表单上,您必须选择一个项目才能显示表单。我遇到的问题是,在提交时,它隐藏了表单。我该怎么纠正呢 这是我的剧本:Javascript 表格在提交时隐藏,javascript,jquery,forms,Javascript,Jquery,Forms,在我的表单上,您必须选择一个项目才能显示表单。我遇到的问题是,在提交时,它隐藏了表单。我该怎么纠正呢 这是我的剧本: <script> $(document).ready(function () { $(".orderForm").hide(); $(".choice").each(function () { $(this).click(function () { $(".orderForm").sho
<script>
$(document).ready(function () {
$(".orderForm").hide();
$(".choice").each(function () {
$(this).click(function () {
$(".orderForm").show();
});
});
});
</script>
$(文档).ready(函数(){
$(“.orderForm”).hide();
$(“.choice”)。每个(函数(){
$(此)。单击(函数(){
$(“.orderForm”).show();
});
});
});
以下是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>
148PKI
我也更新了脚本。使用sessionStorage(或适当的polyfill脚本)跨页面加载持久化变量。(注意sessionStorage序列化了数据,因此在获取值时不再是true
,而是字符串“true”
)
我猜sumbit正在重新加载你的页面。您在
$(文档)中有一个.hide
。.ready
。您还可以使用submit()处理submit。是的,它会重新加载页面。如何修复此问题?请在click函数中使用event.preventDefault()。我假设你所说的“提交”就是“点击”?@Military911你能分享一下.choice
和的相关标记样本吗?谢谢。现在我明白了你是怎么做的,信用卡部分应该是一样的,因为两者都绑定在提交按钮上?@Military911很难说,因为它没有包含在你的问题中,但同样的方法很可能也适用于此。我猜没有办法私下发信息,是吧?
$(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;
});
});