gpt4 book ai didi

javascript - js表单填写检查

转载 作者:行者123 更新时间:2023-11-28 00:28:33 24 4
gpt4 key购买 nike

当用户按下“提交”按钮时,我如何才能将用户返回到未填写的字段?

我有这样的东西:

    <!--Contact Name-->
<div class="section" id="inputdiv">
<span class="fieldname">Name:</span>
<input type="text" id="contactname" /> <!-- Nessesary to be filled-->
<script type="text/javascript">
var contactname = new LiveValidation('contactname');
contactname.add(Validate.Presence);
</script>
</div>


<a class="button-more" style="width:903px; float: right; font-size: 15px; margin-top: 15px;" href="">Submit my answers</a>

或者只是这样:

<input type="text" id="contactname" /> <!-- Nessesary to be filled-->

<a href="">Submit my answers</a>

最佳答案

您应该在用户点击“提交”时执行以下代码:

if (document.getElementById('contactname').value=='') document.getElementById('contactname').focus();
else // if the field isn't empty, proceed

编辑:哦,对不起,我刚刚注意到“jquery”标签。它必须在 jQuery 中创建吗?我不懂 jQuery,但您也可以使用上面的代码;)

请记住,您还应该检查服务器端的所有字段,因为一些有经验的用户可能很容易操纵客户端代码。

关于javascript - js表单填写检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3820658/

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