首页 » 后端 » DedeCMS » 正文

为DedeCMS的自定义表单添加JS验证

发布者:站点默认
2013/06/30 浏览数(2,259) 分类:DedeCMS 为DedeCMS的自定义表单添加JS验证已关闭评论

第一步:

修改 /templets/plus/post_diyform.htm 添加以下代码(建议放到body标签里、form后边):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<script type="text/javascript" src="/images/js/j.js"></script>
<script type="text/javascript">
function chk(){
  var checked = true;
  if(checked){
    $('#form input').each(function(i,e){
      if($(this).val() == ''){
        var tip = $(this).parents('tr').children('td').eq(0).html().replace(':','');
        alert('请填写 '+tip+' !');
        $(this).focus();
        checked = false;
        return false;
      }
    });
  }
  if(checked){
    $('#form textarea').each(function(i,e){
      if($(this).val() == ''){
        var tip = $(this).parents('tr').children('td').eq(0).html().replace(':','');
        alert('请填写 '+tip+' !');
        $(this).focus();
        checked = false;
        return false;
      }
    });
  }
  if(checked){
    return true;
  }else{
    return false;
  }
}
</script>

第二步:

给form添加 onsubmit=”return chk();”

<完>

点击返回顶部
  1. 留言
  2. 联系方式
Loading...