首先在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. 对 /etc/rc.d/init.d 目录的一点理解

    转载 一.Linux的引导过程 系统启动之后,在进入init.d之前,我们先来看看系统都做了什么工作.系统加电之后,首先进行的硬件自检,然后是bootload对系统的初始化,加载内核. 内核被加载到内 ...

  2. VUE系列二:vue基础

    一.组件嵌套 1. 新建一个组件Users.vue <template> <div class="users"> <ul> <li v-f ...

  3. JUnit4时间(超时)测试实例

    “时间测试”是指,一个单元测试运行时间是否超过指定的毫秒数,测试将终止并标记为失败. import org.junit.*; /** * JUnit TimeOut Test * @author yi ...

  4. 转载:erlang实现安卓和IOS的推送。

    erlang-百度云推送Android服务端功能实现-erlang erlang -- ios apns provider -- erlang 实现 转自:http://www.cnblogs.com ...

  5. server2008,本机可以登录ftp,其他机器登录不了解决办法。肯定是防火墙的问题

    转自http://kkworms.blog.51cto.com/540865/558477 今天在windows server 2008 R2上安装了FTP,安装过程如下,然后添加内置防火墙设置,设置 ...

  6. 关于WSDL的理解

    WSDL是由types, message, portType组成. 而binding, service则是具体的绑定. portType有哪些operation. 然后是portType的Endpoi ...

  7. 删除mac系统win10启动选择项

    打开终端输入:diskutil list找到EFI这个分区,挂载EFI分区diskutil mount /dev/disk0s1 回到Finder 删除除apple之外的两个文件夹就可以了(删除win ...

  8. 获取设备和 App 信息

    设备对照表:https://www.theiphonewiki.com/wiki/Models 获取设备和 App 信息代码: NSLog(@"设备信息如下"); NSLog(@& ...

  9. windows下更改鼠标滚轮方向

    本来鼠标滚轮的方向无所谓“正确”与否(win下和mac下方向相反),只要习惯即可.但从win下切换到mac后,本来是想把鼠标方向调成跟win下一致,结果这么一反转,连多指手势的“左右”都反了,苹果,算 ...

  10. 如何在Datatable中取得每列的数据列宽度

    你用SqlDataAdapter填充DataTable的时候不要用Fill方法而应该用FillSchema方法: using (SqlConnection conn = new SqlConnecti ...