关于js函数调用验证表单问题

Cheny1m 2019-05-03 11:23:02
在提交表单时没有按预期提示出红色字体 应该是js函数没有被调用 求大佬看一看是什么问题 代码如下 <!DOCTYPE html><html lang="en"><head> <title>用户信息提交页面</title> <style> body{ text-align:center } div{ margin:0 auto; width:430px; } #header{ border-width:1px; border-style: solid; border-color: rgb(199, 197, 197); border-top-left-radius: 4px; border-top-right-radius: 4px; text-align:left; text-indent: 15px; background-color:rgb(240, 240, 240); font-size: 18px; font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; padding-top:15px; padding-bottom: 15px; } #content{ width:405px; padding-left: 25px; border-left:solid 1px rgb(199, 197, 197); border-right: solid 1px rgb(199, 197, 197); padding-top:35px; text-align: left; font-size:16px; font-family: 黑体; line-height: 25px; } #footer{ border-left:solid 1px rgb(199, 197, 197); border-right: solid 1px rgb(199, 197, 197); border-bottom: solid 1px rgb(199, 197, 197); border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; padding-top: 20px; padding-bottom: 30px; font-size:12px; } #tips{ font-size:12px; color:red; } </style> <script> function validateForm(){ var x1=document.forms["myForm"]["姓名"].value; var x2=document.forms["myForm"]["学号"].value; var x3=document.forms["myForm"]["电话"].value; var x4=document.forms["myForm"]["邮箱"].value; if (x1==null||x1==''){ document.getElementById("tips").innerHTML="姓名不能为空!"; return false; }else if(x2==null||x2==''){ document.getElementById("tips").innerHTML="学号不能为空!"; return false; }else if(document.getElementById("boy").checked==false&&document.getElementById("girl").checked==false){ document.getElementById("tips").innerHTML="性别必须选择!"; return false; }else if(x3==null||x3==''){ document.getElementById("tips").innerHTML="电话不能为空!"; return false; }else if(x4==null||x4==''){ document.getElementById("tips").innerHTML="邮箱不能为空"; return false; }else{ window:alert("提交成功!"); return false; } } </script></head><body> <div id="header"> <span>提交用户信息</span> </div> <div id="content"> <form name="myForm" onsubmit="return validateForm()" method="post"> <p id="tips" name="tishi"></p> <span>姓名*    <input type="text" style="width:300px;" name="姓名" ></span><br> <span>学号*    <input type="text" style="width:300px;" name="学号" ></span><br> <span>性别*   <input type="radio" name="gander" id="boy" value="1">男 <input type="radio" name="gander"id="girl" value="2" >女</span><br> <span>电话*    <input type="text" style="width:300px;" name="电话"></span><br> <span>邮箱*    <input type="text" style="width:300px;" neme="邮箱"></span><br> </div> <div id="footer"> <input type="submit" value="提交"> <input type="reset" value="取消"> </div></form></body></html> 图中是预期结果 但我的代码不能实现 求大佬指点迷津!!
...全文
327 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cheny1m 2019-05-07
  • 打赏
  • 举报
回复
引用 1 楼 丰云的回复:
当学会了优秀的代码格式,才能学会如何调试问题,那么,这种简单的问题根本不需要问。 相反,杂乱的代码,会让简单的问题变得无法识别,高手也没法帮你,心烦。。。
问题解决了 至于代码格式是复制上来之后才变成这样子的。。 还是谢谢大佬的意见。
丰云 2019-05-05
  • 打赏
  • 举报
回复
当学会了优秀的代码格式,才能学会如何调试问题,那么,这种简单的问题根本不需要问。 相反,杂乱的代码,会让简单的问题变得无法识别,高手也没法帮你,心烦。。。

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧