// 页面初始化 $(document).ready(function() { $("#mains").attr("class", "move-ins"); onhandler(); }); // ajax后事件重新绑定 function onhandler() { //$("a").off("click"); //菜单事件绑定 $(".menu li").on('click', 'a', function() { if (!$(this).hasclass("active")) { $(".menu li a").removeclass("active"); $(this).addclass("active"); } }); $("a[class != moveindex][ target != _blank]").on('click', function(events) { $.pjax.click(event, { container: "#main", fragment: "#main", scrollto: false }); }); /*$("a[class = moveindex]").on('click', function(events) { $.pjax.click(event, { container: "body", fragment: "body" }); })*/ // 留言版块 if ($(".guestbook-form").length > 0) { $(".guestbook-submit,.comment-replay").off("click"); $(".guestbook-submit").on('click', function() { var isform = $(".guestbook-form"); if (check(isform[0])) { commentpost(isform.serialize()); } }); $(".comment-replay").on('click', function() { var id = $(this).attr("data-id"); var name = $('#commentid-' + id + ' h3').html(); commentreplay(id, name); }); } // 评论版块 if ($(".comment-form").length > 0) { $(".comment-submit,.comment-replay").off("click"); $(".comment-submit").on('click', function() { var isform = $(".comment-form"); if (check(isform[0])) { commentpost(isform.serialize()); } }); $(".comment-replay").on('click', function() { var id = $(this).attr("data-id"); var name = $('#commentid-' + id + ' h3').html(); commentreplay(id, name); }); } } // 验证表单 function check(obj) { if (!obj) { $.munmodal.message({ type: "error", content: "系统错误!" }); return false; } if (obj.name.value == "" || obj.name.value.length < 2) { $.munmodal.message({ type: "error", content: "昵称没有填好!" }); return false; } if (obj.tel.value == "" || !/^1[34578]\d{9}$/.test(obj.tel.value)) { $.munmodal.message({ type: "error", content: "手机号填错了吧!" }); return false; } if (obj.email.value == "" || !/.+@.+\.[a-za-z]{2,6}$/.test(obj.email.value)) { $.munmodal.message({ type: "error", content: "邮箱填错了吧!" }); return false; } if (obj.content.value == "" || obj.content.value.length < 4) { $.munmodal.message({ type: "error", content: "你倒是写点东西啊!" }); return false; } return true; } function commentpost(mydata) { var myurl; if ($(".guestbook-form").length > 0) { myurl = $(".guestbook-form")[0].action; } else { myurl = $(".comment-form")[0].action; } $.ajax({ cache: false, url: myurl, type: "post", data: mydata, success: function(data) { if (data == "error") { $.munmodal.message({ type: "error", content: "系统错误!" }); } else if(data == "验证码错误!"){ $.munmodal.message({ type: "error", content: "验证码错误!" }); } else { $(".comment-list").find("li").eq(0).before(data); $(".comment-list").find("li").eq(0).attr("class", "move-in"); $.munmodal.message({ type: "success", content: "提交成功,感谢支持!" }); $("#myform input,#myform textarea").val(""); ongetcode(); } } }); }