前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >emlog纯js实现打钩防止垃圾评论

emlog纯js实现打钩防止垃圾评论

作者头像
Youngxj
发布2018-06-06 15:26:35
1.3K0
发布2018-06-06 15:26:35
举报
文章被收录于专栏:YoungxjYoungxj

第一步、在全局js中加入如下代码:里面的一些正则可以自行替换成你想要的

代码语言:javascript
复制
function SLyz(){
if(document.commentform.comname.value.length == 0){alert("请输入昵称");document.commentform.comname.focus();return false;}
var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;if(document.commentform.commail.value.length == 0 && !reg.test(document.commentform.commail.value)){alert("1、邮箱地址是否填写 \r\n2 、邮箱地址是否正确");document.commentform.commail.focus();return false;}
var reg = /^(http:\/\/|https:\/\/)([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/;if(!reg.test(document.commentform.comurl.value) && (document.commentform.comurl.value)){alert("网址格式必须加http://或https://且网址结尾不能有“/”;次选为选填项,可不填写");document.commentform.comurl.focus();return false;}
if(document.commentform.comment.value.length == 0){alert("请填写评论内容且评论内容需包含中文");document.xj.comment.focus();return false;}
}

第二步、在模板文件module.php中找到代码:

代码语言:javascript
复制
<form method="post" name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform">

修改为以下代码:

代码语言:javascript
复制
<form method="post" name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform" onSubmit="return SLyz();">

第三步、在提交评论按钮后面添加复选框和提示语句:

代码语言:javascript
复制
<input type="checkbox" value="9" id="sheli" name="sheli" required="required" autocomplete="on" title="发表评论确认框:请勾选我再发表评论!"> <font color="red">请勾选我再发表评论!</font>

完成以上三步就可以实现打钩防止垃圾评论。

原文地址:舍力博客

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-6-18 2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档