用js写留言信息的判断非空条件
首先在tp上有多种方法去判断留言是否为空,但是js是最方便也是最没有冲突的。
<form action="{:U('validate')}" method="post" name="myform">
<input type="hidden" name="lanmu" value="">
<li>
<div class="main_ly_t1"><em>留言标题:</em><input type="text" name="lc_title" id="lc_title" required> <span style="color:#C39766;">*</span></div>
<div class="clear"></div>
</li>
<li>
<div class="main_ly_t1"><em>姓名:</em><input type="text" name="lc_name" id="lc_name" required><span style="color:#C39766;">*</span></div>
<div class="clear"></div>
</li>
<li>
<div class="main_ly_t1"><em>E-MAIL:</em><input type="text" name="lc_email" id="lc_email" required><span style="color:#C39766;">*</span></div>
<div class="clear"></div>
</li>
<li>
<div class="main_ly_t1"><em>联系电话:</em><input type="text" name="lc_tel" id="lc_tel" required><span style="color:#C39766;">*</span></div>
<div class="clear"></div>
</li> <li>
<div class="main_ly_t1"><em>留言内容:</em><textarea name="lc_content" id="lc_content" required></textarea></div>
<div class="clear"></div>
</li>
<li>
<div class="yao">
<div class="main_ly_t2"><input type="submit" id="tijiao" value="提 交" onClick="return doSubmit();" style="background:#000; border-radius:5px;border:0;"></div>
<div class="main_ly_t3"><input type="reset" id="chongzhi" value="重 置" style="background:#000; border-radius:5px; border:0;"></div>
</div>
</li>
<div class="clear"></div>
</form>
现在有一个点击事件doSubmit(),我们做一个判断信息是否为空,给出提示,并赋予焦点。
<script type="text/javascript">
function doSubmit(){
if (document.getElementById("lc_title").value==""){
alert("亲,请填写留言标题!");
document.getElementById("lc_title").focus(); //赋予焦点
return false;
}
if (document.getElementById("lc_name").value==""){
alert("亲,请填写您的姓名!");
document.getElementById("lc_name").focus();
return false;
}
if (document.getElementById("lc_email").value==""){
alert("亲,请填写电子邮件!");
document.getElementById("lc_email").focus();
return false;
}
if (!Isyx(document.getElementById("lc_email").value)){
alert("亲,请输入正确的电子邮件!");
document.getElementById("lc_email").focus();
return false;
}
if (document.getElementById("lc_tel").value==""){
alert("亲,请填写联系方式!");
document.getElementById("lc_tel").focus();
return false;
}
var reg =/(^{,}[||||||][-]{}$)/; //判断手机填写信息是否为正确手机号
if(!reg.test(document.getElementById("lc_tel").value)){
alert("亲,请输入正确的联系方式!");
document.getElementById("lc_tel").focus();
return false;
}
if (document.getElementById("lc_content").value==""){
alert("亲,请填写留言内容!");
document.etElementById("lc_content").focus();
return false;
}
return true;
} </script>
这样就可以实现了
用js写留言信息的判断非空条件的更多相关文章
- js表单序列化时,非空判断
在项目中,对于数据的传输一般需要非空的判断,而数据字段较多时一般直接将表单序列化,此时如何判断非空,如下 因为将表单序列化时,数据格式为 trainKind=1&trainKindCode=1 ...
- javascript判断非空
/* *判断非空 * */ function isEmpty(val){ if(val == null)return true; if(val == undefined || val == 'unde ...
- Java中判断非空对象.
Java中经常会遇到判断非空的时候. 有的时候判断了非空但是还是报空指针,为什么.? 判断的时候一般都会判断两次.类似于: Org o = new Org(); if ( o.getId()!=nul ...
- JavaScript如何判断非空
JavaScript判断非空的语句一般为: var elvis; if (typeof elvis !== "undefined" && elvis !== nul ...
- JS中if判断 非空即为真 非0即为真
1.字符串参与判断时:非空即为真判断字符串为空的方法if(str!=null && str!=undefined && str !='')可简写为if(!str){ ...
- C++ 中判断非空的错误指针
最近在写网络上的东西,程序经过长时间的运行,会出现崩溃的问题,经过DUMP文件的查看,发现在recv的地方接收返回值的时候,数据的长度异常的大差不多16亿多字节.而查看分配后的char指针显示为错误的 ...
- Mybatis if test 中int判断非空的坑
Mybatis 中,alarmType 是int类型.如果alarmType 为0的话,条件判断返回结果为false,其它值的话,返回true. <if test="alarmType ...
- JAVA非空条件三元运算符
//非空情况处理: // Integer holidayPrice = order.get("holidayPrice")!=null?Integer.valueOf(String ...
- Mybatis if test 中int integer判断非空的坑
Mybatis 中,alarmType 是int类型.如果alarmType 为0的话,条件判断返回结果为false,其它值的话,返回true. 1 <if test="alarmTy ...
随机推荐
- SpringMVC系列(十三)异常处理
一.简介 • Spring MVC 通过 HandlerExceptionResolver 处理程序的异常,包括 Handler 映射.数据绑定以及目标方法执行时发生的异常.• SpringMVC 提 ...
- e613. Modifying the Focus Traversal Order
JFrame frame = new JFrame(); JButton component1 = new JButton("1"); JButton component2 = n ...
- 【C/C++学院】0904-boost智能指针/boost多线程锁定/哈希库/正則表達式
boost_array_bind_fun_ref Array.cpp #include<boost/array.hpp> #include <iostream> #includ ...
- iText操作PDF读取JPEG图片ArrayIndexOutOfBoundsException异常
iText版本:itextpdf-5.5.1.jar 问题描述 读取本地JPEG图片文件的代码: com.itextpdf.text.Image image = com.itextpdf.text.I ...
- 使用spring initialization创建SpringBoot项目
https://blog.csdn.net/liutong123987/article/details/79385513 有很多方法可以快速创建Springboot项目,可以通过idea的spring ...
- python unittest 3- 框架Nose
当前python的测试框架主要有以下三个: 1)zope.testing 2)py.test 3)Nose Nose下载:https://github.com/nose-devs/nose 1.Nos ...
- javascript的console命令
1.分类输出 console.log('文字信息'); console.info('提示信息'); console.warn('警告信息'); console.error('错误信息'); 2.分组输 ...
- 代码记录——phase16,block36
36*36 -2,-2扩展 代码有问题,有时能运行有时报错. HRESULT RotateZoom(PBYTE pbSrc,int iWidth,int iHeight,double dbRotate ...
- shell脚本自动清理服务器日志、图片等信息
在做性能测试的时候,linux服务器时常会产生大量数据,如日志信息,图片信息,文件信息等,压测一段时间后,导致服务器磁盘空间暂满而崩溃,每天手动清理比较麻烦, 利用shell脚本自动清理,脚本如下 1 ...
- [scala] scala 函数 (⑦)
1.scala 函数定义 2.scala 高阶函数 3.匿名函数 4.柯里化 import scala.math._ /** * @author xwolf * @date 2017-04-24 9: ...