• 为我的blogs添加评论


    将下面代码添加到文章HTML末尾

    CODE:

    <div id="MySignature" style=" 100%;">
    <hr style="background-color: lime; height: 2px; margin-left: 10px;" />
    <div id="leowlComment" style=" 561px; border: #ffffff 0px inset;">       <span style="color: #ff0000;">您对本文的宝贵意见:</span><br/>        <span style="margin-left: 50px;"><input name="fc1" type="button" value="强烈推荐" style="background-color: #006600;" /> <input name="fc2" type="button" value="好文支持" style="background-color: #ffff82;" /> <input name="fc3" type="button" value="楼主加油" style="background-color: #ff89ff;" /> <input name="fc4" type="button" value="我踩一脚" style="background-color: #2400cf;" /> <input name="fc5" type="button" value="我来拍砖" style="background-color: #ccffff;" /> <input name="fc7" type="button" value="我仅路过" style="background-color: #c8c8c8;" /> </span><br/><span style="color: #5e1b00;">感谢您的鼓励和批评,它将是我进步的<big>动力</big></span> </div>
    <hr style="background-color: lime;  98%; height: 2px; margin-left: 10px;" />
    <script type="text/javascript">// <![CDATA[
    var commentAuthorHasChecked = false;
    var commentAuthorIsValid = false;
    var commentUrlIsValid = true;
    var commentEmailIsValid = true;
    var authenCodeHasChecked = false;
    var authenCodeIsValid = true;
    var hasLogined = false;
    var isPost = false;
    
    $(function() {
        $("input[name=fc1]").click(function() {
            if (!isPost) {
                alert("ok");
                $("div[class=diggit]").trigger('click');
                $("textarea[class=comment_textarea]").val("好文我顶,推荐一下!");
                PostComment();
                isPost = true;
            }
        });
        $("input[name=fc2]").click(function() {
            if (!isPost) {
                $("textarea[class=comment_textarea]").val("楼主辛苦,支持一下!");
                PostComment();
                isPost = true;
            }
        });
        $("input[name=fc3]").click(function() {
            if (!isPost) {
                $("textarea[class=comment_textarea]").val("文章不错,楼主继续加油!");
                PostComment();
                isPost = true;
            }
        });
        $("input[name=fc4]").click(function() {
            if (!isPost) {
                $("textarea[class=comment_textarea]").val("我来踩一脚,期待楼主的好文。");
                PostComment();
                isPost = true;
            }
        });
        $("input[name=fc5]").click(function() {
            if (!isPost) {
                $("textarea[class=comment_textarea]").val("我专程过来拍砖头的");
                PostComment();
                isPost = true;
            }
        });
        $("input[name=fc7]").click(function() {
            if (!isPost) {
                $("textarea[class=comment_textarea]").val("我仅路过,凑个热闹^_^");
                PostComment();
                isPost = true;
            }
        });
    });
    function PostComment() {
    
        var isValid = true;
    
        if ($("#wrapAuthenCode").css("display") == "none") {
            ShowAuthenCode();
            $("#tip_AuthenCode").css("color", "red");
            $("#tip_AuthenCode").html("请输入验证码!");
            isValid = false;
        }
    
        if (!hasLogined && !commentAuthorHasChecked) {
            CheckAuthor();
        }
        if (!hasLogined && !commentAuthorIsValid) {
            isValid = false;
        }
    
        if (!authenCodeHasChecked) {
            CheckAuthenCode();
        }
        if (!authenCodeIsValid) {
            isValid = false;
        }
    
        if (!hasLogined && !commentUrlIsValid) {
            isValid = false;
        }
        if (!commentEmailIsValid) {
            isValid = false;
        }
        if (!CheckCommentContent()) {
            isValid = false;
        }
        if (!isValid) {
            return;
        }
    
        var content = $("#tbCommentBody").val();
        if (content.length > 2000) {
            alert("评论内容过长!不允许发布!");
            return;
        }
    
        if (content.indexOf(" E         E          E      ") >= 0) {
            alert("该内容不允许布!");
            return;
        }
    
        if ($("#span_comment_posted").html() != '' && $("#span_comment_posted").html() == content) {
            alert("该评论已发表过!");
            return;
        }
    
        $("#tip_comment").html("评论提交中...");
        $("#span_comment_posted").html(content);
        //content = content.replace("'", "\\'");
        var email = $("#tbCommentEmail").val();
        var authenNum = $("#tbAuthenCode").val();
        var authenId = $("#span_comment_test").html();
        var comment = {};
        comment.authenNum = authenNum;
        comment.authenId = authenId;
        comment.parentId = 1716791;
        comment.blogId = 44053;
        comment.sourceUrl = 'http://www.cnblogs.com/gnielee/archive/2010/04/21/blog-statistics-by-wpf4.html';
        comment.author = $("#tbCommentAuthor").val();
        comment.url = $("#tbCommentAuthorUrl").val();
        comment.authenCode = $("#tbAuthenCode").val();
        comment.email = email;
        comment.title = '统计个人博客园文章数据(WPF4 版)';
        comment.content = content;
        comment.parentCommentId = $("#span_parentcomment_id").html();
        $.ajax({
            url: '/ws/CommentService.asmx/AddAnonymousComment',
            data: $.toJSON(comment),
            type: "post",
            dataType: "json",
            contentType: "application/json; charset=utf8",
            success: function(data) {
                if (data.d["IsSuccess"]) {
                    ShowCommentMsg("感谢您的回复:)");
                    //RereshComments2(comment.parentId);
                    $("#tbCommentBody").val('');
                    //$("#divCommentShow").html(data.d["ReturnData"]+content.replace(/\n/g,"<br />")+"<br /><br />");
                    $("#divCommentShow").html($("#divCommentShow").html() + data.d["ReturnData"]);
                    $("#tip_AuthenCode").html('');
                    RefreshAuthenCode();
                    $("#tbAuthenCode").val("");
                    CommentNotify(data.d["CommentID"]);
                }
                else {
                    ShowCommentMsg(data.d["ReturnData"]); //"抱歉!评论提交失败!请与管理员联系。");
                    $("#span_comment_posted").html('');
                }
            },
            error: function(xhr) {
                ShowCommentMsg("抱歉!评论提交失败!请与管理员联系。");
                $("#span_comment_posted").html('');
                //alert(xhr.responseText);
            }
        }
            );
    }
    
    function RefreshAuthenCode() {
        AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode", "{}", RefreshImg);
        $("#lnkRereshAuthenCode").html("<span style='color:red'>刷新中...</span>");
        return false;
    }
    
    function RefreshImg(response) {
        $("#imgAuthenCode").attr("src", "/Modules/CaptchaImage/ValidCodeImage.aspx?id=" + encodeURIComponent(response));
        $("#span_comment_test").html(response);
        $("#lnkRereshAuthenCode").html("看不清,换一个");
    }
    
    function ShowAuthenCode() {
        //if($("#wrapAuthenCode").css("display")=="none"){    
        //    AjaxPost("/ws/CommentService.asmx/RefreshAuthenCode","{}",ShowAuthenCodeOk);
        //}
        $("#wrapAuthenCode").show();
    }
    
    function ShowAuthenCodeOk(response) {
        UpdateAuthenCode();
        $("#tbAuthenCode").val("");
        $("#wrapAuthenCode").show();
        $("#tip_AuthenCode").html('');
    }
    
    
    function CheckAuthor(isOnblur) {
        commentAuthorHasChecked = true;
        var maxLength = 30;
        if ($("#tbCommentAuthor").val().length == 0) {
            $("#tip_author").html("请输入您的昵称!");
            commentAuthorIsValid = false;
            return false;
        }
        else if ($("#tbCommentAuthor").val().length > maxLength) {
            $("#tip_author").html("昵称不允许超过" + maxLength + "个字符!");
            commentAuthorIsValid = false;
            return false;
        }
        else {
            //if(isOnblur){
            AjaxPost("/ws/CommentService.asmx/IsAuthorExist", "{author:'" + $("#tbCommentAuthor").val() + "'}", OnCheckAuthorExist);
            //}
            //else{
            //    $("#tip_author").html("");
            //    commentAuthorIsValid = true;
            //}
            return true;
        }
    }
    
    function OnCheckAuthorExist(response) {
        if (!response) {
            $("#tip_author").html("");
            commentAuthorIsValid = true;
        }
        else {
            $("#tip_author").html("该昵称已被使用,请更换昵称");
            commentAuthorIsValid = false;
        }
    }
    
    function CheckUrl() {
        var maxLength = 50;
        var url = $("#tbCommentAuthorUrl").val();
    
        if (url.length == 0) {
            commentUrlIsValid = true;
            return true;
        }
        else if (url.length > maxLength) {
            $("#tip_url").html("主页地址不允许超过" + maxLength + "个字符!");
            commentUrlIsValid = false;
            return false;
        }
        else if (url.indexOf("http://") != 0 || url.indexOf(".") < 0) {
            $("#tip_url").html("主页地址要以“http://”开头");
            commentUrlIsValid = false;
            return false;
        }
        else {
            $("#tip_url").html("");
            commentUrlIsValid = true;
            return true;
        }
    }
    
    function CheckEmail() {
        var email = $("#tbCommentEmail").val();
        if (email.length > 0) {
            var regExp = new RegExp("\\w+@((\\w|\-)+\\.)+[a-z]{2,3}");
            if (!regExp.test(email)) {
                $("#tip_email").html("请输入正确的邮件地址!");
                commentEmailIsValid = false;
            }
            else {
                commentEmailIsValid = true;
                $("#tip_email").html("");
            }
        }
        else {
            commentEmailIsValid = true;
            $("#tip_email").html("");
        }
    }
    
    function CheckAuthenCode() {
        authenCodeHasChecked = true;
        var num = $("#tbAuthenCode").val();
        var id = $("#span_comment_test").html();
        $("#tip_AuthenCode").css("color", "red");
        if (num.length == 0) {
            authenCodeIsValid = false;
            $("#tip_AuthenCode").html("请输入验证码!");
            return;
        }
        else if (num.length != 4) {
            authenCodeIsValid = false;
            $("#tip_AuthenCode").html("请输入四位数字!");
            return;
        }
        else if (new RegExp("(\d+)").test(num)) {
            authenCodeIsValid = false;
            $("#tip_AuthenCode").html("请输入四位数字!");
            return;
        }
        else {
            AjaxPost("/ws/CommentService.asmx/CheckAuthenCode", "{number:" + num + ",id:'" + id + "'}", OnCheckAuthenCode);
        }
    }
    
    function OnCheckAuthenCode(response) {
        if (response) {
            $("#tip_AuthenCode").css("color", "green");
            $("#tip_AuthenCode").html("验证码输入正确!");
            authenCodeIsValid = true;
        }
        else {
            $("#tip_AuthenCode").css("color", "red");
            $("#tip_AuthenCode").html("验证码输错啦!");
            RefreshAuthenCode();
            authenCodeIsValid = false;
        }
    }
    
    function CheckCommentContent() {
        if ($("#tbCommentBody").val().length == 0) {
            alert("请输入评论内容!");
            return false;
        }
        return true;
    }
    // ]]></script>
    </div>
    

    效果图:

  • 相关阅读:
    spring配合junit测试 initializationError 错误
    hashmap为什么不安全
    关于使用iframe标签自适应高度的使用
    关于highcharts(功能强大、开源、美观、图表丰富、兼容绝大多数浏览器的纯js图表库)
    富文本web编辑器(UEditor)
    css行级块级区别总结摘录
    jquery mobile 主题
    jquery mobile selectmenu下拉菜单
    jquery mobile popup 弹出窗口
    jquery mobile navbar
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1761739.html
Copyright © 2020-2023  润新知