html中有关于submit的笔记

xiaoxiao2021-02-28  84

用input提交,代码如下:

<form id="TestForm" name="SelectNav" method="post" action="goto.php"> <input class="shuju" id="TestInput" name="TestInput" type="text" placeholder="在这里填写信息" autocomplete="off"/> <input class="tijiao" type="submit" name="TestSubmit" value="提 交" onclick="return check()"/> <input class="chongzhi" type="reset" name="TestReset" value="重 置" /> </form>

  判断数据不能为空:

<script> function check(){ if(TestForm.TestInput.value==""){ alert("请填写信息!"); return false; } TestForm.TestSubmit(); } </script>

用a标签提交,代码如下:·

<form id="TestForm" name="SelectNav" method="post" action="goto.php"> <input class="shuju" id="TestInput" name="TestInput" type="text"placeholder="在这里填写信息" autocomplete="off"/> <a onclick="TestSubmit();">提交</a> </form>

  核对信息是否正确:

<script> function TestSubmit(){ var xx="请核对信息是否有误:\r\n测试信息:("+TestForm.TestInput.value+")"; if(confirm(xx)){ document:TestForm.submit(); }else{ return false; } } </script>

  判断信息是否为空:

<script> function TestSubmit(){ if(TestForm.TestInput.value==""){ alert('信息为空,不能提交!'); }else{ document:TestForm.submit(); } } </script>

  判断手机号是否为空,并验证格式是否正确:

<script> function TestSubmit(){ var phone = document.getElementById('TestInput').value; if(phone==""){ alert('信息为空,不能提交!'); }else if(!(/^1[34578]\d{9}$/.test(phone))){ alert("手机号码格式不正确!"); }else{ document:TestForm.submit(); } } </script>

  判断邮箱是否为空,并验证格式是否正确:

<script> function TestSubmit(){ var email = document.getElementById('TestInput').value; if(email==""){ alert('信息为空,不能提交!'); }else if(!(/^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/.test(email))){ alert("邮箱格式不正确!"); }else{ document:TestForm.submit(); } } </script>
转载请注明原文地址: https://www.6miu.com/read-2250062.html

最新回复(0)