$(function() { /* 左边菜单 */ $(".prev_pic,.next_pic").hover(function() { $(this).fadeTo("show", 0.5); }, function() { $(this).fadeTo("show", 0.2); }) $(".cat_brand").slide({ effect : "left", autoPlay : false, interTime : 3000, delayTime : 700 }); $("#tmall_nav").slide({ titCell : ".cate_nav li", mainCell : ".tmall_cat_content", autoPlay : false, interTime : 7400, delayTime : 0 }); // 左右切换 $('#myCarousel').carousel({ interval : false }); // 点击显示更多热门推荐 $('#hot_more').click(function() { $('.hot-more').show(); $('.cat_detail').hide(); }); $('.cate_nav li').click(function() { $('.hot-more').hide(); $('.cat_detail').show(); }); viewSTuanEvent(); stuanJoin(); replyContentLengthLimit(); btnReplyEvent(); }); function btnReplyEvent() { $("#btnReply").click(function() { var tuanNo = $(this).attr("tuan_no"); var infoId = $(this).attr("info_id"); $.post("stuan_info_comment.htm", { 'tuanNo' : tuanNo, 'infoId' : infoId, 'content' : $("#replyContent").val() }, function(result) { if (result.succee) { var replyLi = createReplyli(result.comment); $("div.evaluate-cont ul").append(replyLi); $("#replyContent").val(""); } else { alert(result.msg); } }, "json"); }); } /** * 创建回复的tr标签 * * @param value * @returns {String} */ function createReplyli(value) { var reply = ''; if (value) { reply = reply + '
  • '; reply = reply + '
    '; reply = reply + ' '; if (value.comment_user_image || '') { reply = reply + ' '; } else { reply = reply + ' '; } reply = reply + ' '; reply = reply + '
    '; reply = reply + '
    '; reply = reply + ' '; if (value.comment_user_name || '') { reply = reply + ' ' + value.comment_user_name + ' '; } else { reply = reply + ' ' + value.comment_login_name + ' '; } reply = reply + ' '; var newDate = new Date(); newDate.setTime(value.comment_date); reply = reply + ' ' + newDate.format('MM月dd? hh:mm') + ' '; reply = reply + '

    ' + value.comment_content + '

    '; reply = reply + '
    '; reply = reply + '
  • '; } return reply; } var _max = $('.replyLengthTip').text();// 随发最大可输入的文字长? /** * 回复内容长度限制? */ function replyContentLengthLimit() { var _area = $('textarea#replyContent');// 文本? var _info = $('.replyTip');// 长度文字提示标签 var _info_length = $('.replyLengthTip');// 长度数字提示标签 var _btn = $('#btnReply');// 回复发布按钮 var _val; _area.bind('keyup change', function() { // 绑定keyup和change事件 _val = $(this).val(); var _cur = getByteLen(_val);// 目前已输入的内容长度 if (_cur == 0 || _cur > _max) { _btn.attr({ "disabled" : "disabled" });// 内容长度超出,则禁用发布按钮 _btn.addClass("btn-disabled"); } else { _btn.removeAttr("disabled");// 内容长度未超出,则启用发布按? _btn.removeClass("btn-disabled"); } if (_cur <= _max) {// 当默认值小于限制数?可输入数为max-cur _info.text("还可以输?); _info_length.css("color", "#777"); _info_length.text(_max - _cur); } else {// 当默认值大于等于限制数? _info.text("已超?); _info_length.text(_cur - _max); _info_length.css("color", "red"); } }); } /** * 计算字符串的长度(一个汉?或者中文符?算一个长度,两个字母(或英文符?或数字算一个长度) * * @param val * @returns */ function getByteLen(val) { var len = 0; for (var i = 0; i < val.length; i++) { if (val[i].match(/[^\x00-\xff]/ig) != null) // 全角 len += 1; else len += 0.5; } return Math.ceil(len); } /** * 报名 */ function stuanJoin() { jQuery.validator.addMethod("phone", function(value, element, param) { var tel = /^1\d{10}$/; return this.optional(element) || (tel.test(value)); }, $.validator.format("请输入正确的手机号码")); $("#stuan_signUp_form").validate({ submitHandler : function(form) { $.post("joinSTuan.htm", { 'tuanNo' : $("#st_tuan_no").val(), 'phone' : $("#st_phone").val() }, function(result) { if (result.succee) { $("#btn-signUp").hide(); $("#btn-isSignUp").show(); alert(result.msg); } else { if (!result.isLogin) { window.location.href = $("#btn-signUp .btn").attr("href"); } } }, "json"); }, rules : { "phone" : { required : true, phone : true } }, messages : { "phone" : { required : "请输入手机号? } }, success : function(label, element) { // 正确时的样式 label.text(" ").addClass("success"); // 正确时的样式 $(element).removeAttr("style"); }, onkeyup : true, onclick : true, errorPlacement : function(error, element) { error.appendTo(element.parent()); $(error).attr("style", "color:red"); $(element).attr("style", "border:1px solid red"); } }); } /** * 查看S团事件注? */ function viewSTuanEvent() { var $st_tuan_no = $("#st_tuan_no"); var $st_image = $("#st_image"); var $st_title = $("#st_title"); var $st_start_date = $("#st_start_date"); var $st_end_date = $("#st_end_date"); var $st_location = $("#st_location"); var $st_content = $("#st_content"); var $st_jion_deadline = $("#st_jion_deadline"); var $st_count_limit = $("#st_count_limit"); var $st_need_mobile = $("#st_need_mobile"); var $st_phone = $("#st_phone"); var $st_fee = $("#st_fee"); var $st_announcements = $("#st_announcements"); $st_need_mobile.find("a").attr("readonly", "readonly"); var imageSrc = $st_image.attr("src"); $("#btn-mytuan").click(function() { $("#signUpModal").modal("hide"); }); $("a.viewStuan").unbind(); $("a.viewStuan").click(function() { var tuan_no = $(this).attr("data_id"); $st_phone.removeAttr("readonly"); $.post("viewSTuan.htm", { 'tuanNo' : tuan_no }, function(result) { if (result) { $st_tuan_no.val(result.tuan_no); $st_image.attr("src", imageSrc + result.image); $st_title.text(result.title); $st_start_date.text(result.start_date); $st_end_date.text(result.end_date); $st_location.text(result.location); $st_content.text(result.content); $st_jion_deadline.text(result.jion_deadline); $st_count_limit.text(result.count_limit); if ("1" == result.need_mobile) { $st_need_mobile.show(); } else { $st_need_mobile.hide(); } $st_fee.text(result.fee == 0 ? "免费" : result.fee); $st_announcements.text(result.announcements); if (result.is_my_stuan) { $("#btn-mytuan").show(); $("#btn-signUp").hide(); $("#btn-isSignUp").hide(); $st_phone.attr("readonly", "readonly"); } else { $("#btn-mytuan").hide(); if (result.is_jioned) { $("#btn-signUp").hide(); $("#btn-isSignUp").show(); $st_phone.val(result.jioned_phone); $st_phone.attr("readonly", "readonly"); } else { $("#btn-signUp").show(); $("#btn-isSignUp").hide(); } } $("#signUpModal").modal("show"); } else { alert("查看S团信息失败!"); } }, 'json'); }); } Date.prototype.format = function(format) { var date = { "M+" : this.getMonth() + 1, "d+" : this.getDate(), "h+" : this.getHours(), "m+" : this.getMinutes(), "s+" : this.getSeconds(), "q+" : Math.floor((this.getMonth() + 3) / 3), "S+" : this.getMilliseconds() }; if (/(y+)/i.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)); } for ( var k in date) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length)); } } return format; }