用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 ...
随机推荐
- Unity如何内置Visual Studio
一.问题的起源 软件环境:Unity 2017.3.0f3,Visual Studio 2013 问题描述:在Unity中创建C#脚本后,准备双击打开进行编辑时,出现了Fatal Error. 二.问 ...
- Java如何获得运行线程的优先级?
在Java编程中,如何获得运行线程的优先级? 以下示例使用setPriority()方法打印正在运行的线程的优先级. package com.yiibai; public class GettingT ...
- Lemon OA第2篇:功能解析方法
Lemon OA,整个系统功能也算是比较丰富,OA的很多功能都能看见影子,虽然做得不是很强大 接触Lemon OA,起源于Activiti的学习热情,既然这样,研究Lemon OA的目标有3: 1.L ...
- HTML5 Canvas 超炫酷烟花绽放动画教程
这是一个很酷的HTML5 Canvas动画,它将模拟的是我们现实生活中烟花绽放的动画特效,效果非常逼真,但是毕竟是电脑模拟,带女朋友看就算了,效果还是差了点,呵呵.这个HTML5 Canvas动画有一 ...
- UGUI 加载图片
图片是动态加载的,然后转换为sprite赋值到ugui的按钮上 代码如下 using UnityEngine; using System.Collections; using System.IO; u ...
- 机器学习——大数据与MapReduce
MapReduce是一个分布式计算框架 优点:可在短时间内完成大量工作 缺点:算法必须经过重写,需要对系统工程有一定的理解 使用数据类型:数值型和标称型数据 MapReduce在大量节点组成的集群上运 ...
- UITextView: 响应键盘的 return 事件
UITextFieldDelegate代理里面响应return键的回调:textFieldShouldReturn:.但是 UITextView的代理UITextViewDelegate 里面并没有这 ...
- cocos2d - Changing the image of a CCSprite
CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:@"new_image_name"]; [spri ...
- Memcached存储机制
Memcached存储机制 memcached 内存管理 分析(转) 缓存.缓存算法和缓存框架简介 memcached全面剖析–PDF总结篇
- APP投资 历史 十万到 十亿元的项目
马云又投了课程表APP 1亿元. 还能输入106字 http://www.tuicool.com/articles/ARVN3qI#0-qzone-1-41007-d020d2d2a4e8d1a3 ...