首先在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写留言信息的判断非空条件的更多相关文章

  1. js表单序列化时,非空判断

    在项目中,对于数据的传输一般需要非空的判断,而数据字段较多时一般直接将表单序列化,此时如何判断非空,如下 因为将表单序列化时,数据格式为 trainKind=1&trainKindCode=1 ...

  2. javascript判断非空

    /* *判断非空 * */ function isEmpty(val){ if(val == null)return true; if(val == undefined || val == 'unde ...

  3. Java中判断非空对象.

    Java中经常会遇到判断非空的时候. 有的时候判断了非空但是还是报空指针,为什么.? 判断的时候一般都会判断两次.类似于: Org o = new Org(); if ( o.getId()!=nul ...

  4. JavaScript如何判断非空

    JavaScript判断非空的语句一般为: var elvis; if (typeof elvis !== "undefined" && elvis !== nul ...

  5. JS中if判断 非空即为真 非0即为真

    1.字符串参与判断时:非空即为真判断字符串为空的方法if(str!=null && str!=undefined && str !='')可简写为if(!str){   ...

  6. C++ 中判断非空的错误指针

    最近在写网络上的东西,程序经过长时间的运行,会出现崩溃的问题,经过DUMP文件的查看,发现在recv的地方接收返回值的时候,数据的长度异常的大差不多16亿多字节.而查看分配后的char指针显示为错误的 ...

  7. Mybatis if test 中int判断非空的坑

    Mybatis 中,alarmType 是int类型.如果alarmType 为0的话,条件判断返回结果为false,其它值的话,返回true. <if test="alarmType ...

  8. JAVA非空条件三元运算符

    //非空情况处理: // Integer holidayPrice = order.get("holidayPrice")!=null?Integer.valueOf(String ...

  9. Mybatis if test 中int integer判断非空的坑

    Mybatis 中,alarmType 是int类型.如果alarmType 为0的话,条件判断返回结果为false,其它值的话,返回true. 1 <if test="alarmTy ...

随机推荐

  1. weblogic学习笔记:域创建+应用部署

    参考地址:http://docs.oracle.com/cd/E13222_01/wls/docs92/index.html 文档基于版本:weblogic92 域(domain)是weblogic服 ...

  2. fedora26在编译s3c2440内核时make menuconfig *** Unable to find the ncurses libraries

    [root@fedora-26 linux-2.6.32.2]# make menuconfig *** Unable to find the ncurses libraries or the *** ...

  3. 浅谈你感兴趣的 CLR GC 机制底层

    本文内容是学习CLR.via C#的21章后个人整理,有不足之处欢迎指导. 昨天是1024,coder的节日,我为自己coder之路定下一句准则--保持学习,保持自信,保持谦逊,保持分享,越走越远. ...

  4. js Object.prototype.toString.call()

    Object.prototype.toString.call(obj)使用方法以及原理   这几天看vue-router的源码 发现了Object.prototype.toString.call()这 ...

  5. zhuzher日志log

    val log=sc.textFile("/data/logstash/data/*.log") val rowRDD2=log2.map(line=>(line.split ...

  6. Linq 实现两个对象实例List之间的赋值

    public class UserCopy { public class LoginEntity { public string UserName { get; set; } public strin ...

  7. json字符串使用注意问题

    json本身是字符串,即 json字符串 js使用 要把 json字符串 转为  javascript对象 json字符串转为js对象的方法:jquery的parseJSON var str='[{& ...

  8. 制作做最小的fedora、ubuntu , jeos系统

    之前做过, 2018年4月底,最新的fedora28 .ubuntu18.04发布后,自己又尝试做了下. ubuntu的成功了,比较简单: fedora的其实不用自己去制作,直接定制官方的Atomic ...

  9. 织梦Dedecms容易被挂马文件以及可疑文件汇总

    1. 被植入木马,然后网站打开后自动弹出博彩,赌博,色情网站,一般这种病毒的特征代码如下 二.织梦CMS被挂马清理方法 1.删除增加的管理员service.spider等用户名. 2.删除根目录的as ...

  10. linux环境中,如何通过手动创建crontab文件的方式来设置crontab定时调度任务?

    需求描述: 之前在创建定时任务的时候,都是通过cronab -e的方式进行创建,今天在做通过脚本部署定时任务的时候, 就想,通过crontab -e编辑的定时任务存放在哪个文件里,是否,可以手动的编辑 ...