gpt4 book ai didi

javascript - 使用表单验证隐藏和显示 Div

转载 作者:行者123 更新时间:2023-11-28 18:42:38 26 4
gpt4 key购买 nike

提交后,我试图隐藏“测验”并显示“谢谢”。在我添加 JavaScript 表单验证代码之前一切正常,现在它只是重新加载第一个 div“欢迎”我认为在提交时向操作添加“#thanks”可以解决问题,但事实并非如此。然后尝试向我的表单验证添加“if true”语句最终破坏了表单验证。我正在使用 jquery.validate 按照建议验证我的表单。使用当前代码,它会跳过验证并只显示“谢谢” 如果有人有任何建议,我们将不胜感激。

    <div id="quiz">
<form class="cmxform" id="commentForm" method="get" action="" onSubmit="showHide(); return false;">
<label for="cname">Name</label>
<input id="cname" name="name" size="20" class="required" minlength="2" />
</p>
<p>
<label for="ccompany">Company Title</label>
<input id="ccompany" name="company" size="20" class="required company" minlength="2" />
</p>
<p>
<label for="cnumber">Phone Number</label>
<input id="cnumber" name="number" size="20" class="required number" />
</p>
<p>
<label for="cemail">Email</label>
<input id="cemail" name="email" size="20" class="required email" />
<p></p>
<input class="submit" type="submit" value="Submit" align="center"/>
</form>
</div>

<div id="thanks"><h2>Thank you.</h2>
You will receive an email momentarily
</div>

<script>
$("#begin").click(function(){
$("#quiz").show();
$("#welcome").hide();
});
function showHide(){
$("#thanks").show();
$("#quiz").hide();
};

</script>

最佳答案

我只能说你做错了....虽然你正在做的表单验证可以工作,但有很多好的表单验证 jquery 插件可以简化你的生活并增加更丰富的用户经验。 jquery.validate可能是使用最广泛的库,非常值得使用。

关于javascript - 使用表单验证隐藏和显示 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11198145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com