用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 ...
随机推荐
- Json---Linux下使用Jsoncpp
一.安装 scons 下载地址:http://sourceforge.net/projects/scons/files/scons/2.1.0/scons-2.1.0.tar.gz/download ...
- JUnit断言
在本节中,我们将介绍一些断言方法.所有这些方法都受到 Assert 类扩展了java.lang.Object类并为它们提供编写测试,以便检测故障.下表中有一种最常用的断言方法的更详细的解释. 断言 描 ...
- MyBatis打印输出SQL语句
Hibernate是可以配置 show_sql 显示 自动生成的SQL 语句,用 format_sql 可以格式化SQL 语句,但如果用 mybatis 怎么实现这个功能呢?如果你搜索看一下,基本都是 ...
- mysql4.5 更改密码,登录命令行闪退
登录到命令行 修改密码: 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:mysql> set passwor ...
- HDU 3970 Harmonious Set 容斥欧拉函数
pid=3970">链接 题解:www.cygmasot.com/index.php/2015/08/17/hdu_3970 给定n 求连续整数[0,n), 中随意选一些数使得选出的 ...
- 用iostat对linux硬盘IO性能进行检测
近期公司安装了几台DELL PE2650和2850的服务器,统一安装的是RHLE5.132位系统,而服务器的SCSI硬盘都统一做了raid1.公司老总要求对硬盘IO作统一检测报告,在Linux下找了许 ...
- ffmpeg把ts文件转m3u8并切片
Linux_x86_64流媒体环境:nginx + EasyDarwin-master 客户端播放器:VLC media player 下载windows下的ffmepg二进制版本,请进网站http: ...
- Lambda表达式树解析(下)包含自定义的provider和查询
概述 前面章节,总结了Lambda树的构建,那么怎么解析Lambda表达式树那?Lambda表达式是一种委托构造而成,如果能够清晰的解析Lambda表达式树,那么就能够理解Lambda表达式要传递的正 ...
- java 上传附件的一点积累
1.第一种: File inFile = new File(downfileA);//downfileA是前台传过来的,文件路径String fileName = inFile.getName();S ...
- 通过Nginx反向代理,IIS和apache 共用80端口
#user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error.log notice; #error ...