首页 » 后端 » DedeCMS » 正文

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

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

第一步:

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

<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. 联系方式