/**作者:一些事情 *时间:2012-6-28 *需要结合jquery和Validform和lhgdialog一起使用 ----------------------------------------------------------*/ /*返回顶部*/ /*搜索查询*/ function SiteSearch(send_url, divTgs, channel_name) { var strwhere = ""; if (channel_name !== undefined) { strwhere = "&channel_name=" + channel_name } var str = $.trim($(divTgs).val()); if (str.length > 0 && str != "输入关健字") { window.location.href = send_url + "?keyword=" + encodeURI($(divTgs).val()) + strwhere; window.open(send_url + "?keyword=" + encodeURI($(divTgs).val()) + strwhere) } return false; } /*搜索查询*/ function SiteSearchkwf(divTgs) { var str = $.trim($(divTgs).val()); if (str.length > 0 && str != "输入关健字") { window.location.href = "/search_" + encodeURI($(divTgs).val()) + ".html"; // window.open( "search_" + encodeURI($(divTgs).val()) + ".html") } return false; } /*切换验证码*/ function ToggleCode(obj, codeurl) { $(obj).children("img").eq(0).attr("src", codeurl + "?time=" + Math.random()); return false; } //复制文本 function copyText(txt){ window.clipboardData.setData("Text",txt); $.dialog.tips("复制成功,可以通过粘贴来发送!",2,"32X32/succ.png"); }//全选取消按钮函数,调用样式如: function checkAll(chkobj){ if($(chkobj).text()=="全选"){ $(chkobj).text("取消"); $(".checkall").prop("checked", true); }else{ $(chkobj).text("全选"); $(".checkall").prop("checked", false); } } //积分兑换 function NumConvert(obj){ var maxAmount = parseFloat($("#hideAmount").val()); //总金额 var pointCashrate = parseFloat($("#hideCashrate").val()); //兑换比例 var currAmount = parseFloat($(obj).val()); //需要转换的金额 if(currAmount > maxAmount){ currAmount = maxAmount; $(obj).val(maxAmount); } var convertPoint = currAmount * pointCashrate; $("#convertPoint").text(convertPoint); } /*PROPS选择卡特效*/ function ToggleProps(obj, cssname){ $(obj).parent().children("li").removeClass(cssname); $(obj).addClass(cssname); } //Tab控制选项卡 function tabs(tabId, event) { //绑定事件 var tabItem = $(tabId + " #tab_head ul li a"); tabItem.bind(event,function(){ //设置点击后的切换样式 tabItem.removeClass("current"); $(this).addClass("current"); //设置点击后的切换内容 var tabNum = tabItem.parent().index($(this).parent()); $(tabId + " .tab_inner").hide(); $(tabId + " .tab_inner").eq(tabNum).show(); }); } //显示浮动窗口 function showWindow(objId){ var box = '
' + $('#' + objId).html() + '
'; var tit = $('#' + objId).attr("title"); var dialog = $.dialog({ lock: true, min: false, max: false, resize: false, title: tit, content: box, width: 480, ok: function () { }, cancel: false }); } //执行删除操作 function ExecDelete(sendUrl, checkValue, urlId){ var urlObj = $('#' + urlId); //检查传输的值 if (!checkValue) { $.dialog.alert("对不起,请选中您要操作的记录!"); return false; } var m = $.dialog.confirm("删除记录后不可恢复,您确定吗?", function () { $.ajax({ type: "POST", url: sendUrl, dataType: "json", data: { "checkId": checkValue }, timeout: 20000, success: function(data, textStatus) { if (data.status == 1){ $.dialog.tips(data.msg, 2, "32X32/succ.png", function(){ if(urlObj){ location.href = urlObj.val(); }else{ location.reload(); } }); } else { $.dialog.alert(data.msg); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { $.dialog.alert("状态:" + textStatus + ";出错提示:" + errorThrown); } }); }, function(){ }); } //单击执行AJAX请求操作 function clickSubmit(sendUrl){ $.ajax({ type: "POST", url: sendUrl, dataType: "json", timeout: 20000, success: function(data, textStatus) { if (data.status == 1){ $.dialog.tips(data.msg, 2, "32X32/succ.png", function(){ location.reload(); }); } else { $.dialog.alert(data.msg); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { $.dialog.alert("状态:" + textStatus + ";出错提示:" + errorThrown); } }); } //链接下载 function downLink(point, linkurl){ if(point > 0){ $.dialog.confirm("下载需扣除" + point + "个积分
有效时间内重复下载不扣积分,继续吗?", function () { window.location.href = linkurl; }); }else{ window.location.href = linkurl; } return false; } //=====================发送验证邮件===================== function SendEmail(username, sendurl) { if(username == ""){ $.dialog.alert('对不起,用户名不允许为空!'); return false; } //提交 $.ajax({ url: sendurl, type: "POST", timeout: 60000, data: { username: function () { return username; } }, dataType: "json", success: function (data, type) { if (data.status == 1) { $.dialog.tips(data.msg, 2, "32X32/succ.png", function(){}); } else { $.dialog.alert(data.msg); } }, error: function(XMLHttpRequest, textStatus, errorThrown){ $.dialog.alert("状态:" + textStatus + ";出错提示:" + errorThrown); } }); } /*表单AJAX提交封装(包含验证)*/ function AjaxInitForm(formId, btnId, isDialog, urlId){ var formObj = $('#' + formId); var btnObj = $("#" + btnId); var urlObj = $("#" + urlId); formObj.Validform({ tiptype:3, callback:function(form){ //AJAX提交表单 $(form).ajaxSubmit({ beforeSubmit: formRequest, success: formResponse, error: formError, url: formObj.attr("url"), type: "post", dataType: "json", timeout: 60000 }); return false; } }); //表单提交前 function formRequest(formData, jqForm, options) { btnObj.prop("disabled", true); btnObj.val("提交中..."); } //表单提交后 function formResponse(data, textStatus) { if (data.status == 1) { btnObj.val("提交成功"); //是否提示,默认不提示 if(isDialog == 1){ $.dialog.tips(data.msg, 2, "32X32/succ.png", function(){ if(data.url){ location.href = data.url; }else if(urlObj.length > 0 && urlObj.val() != ""){ location.href = urlObj.val(); }else{ location.reload(); } }); }else{ if(data.url){ location.href = data.url; }else if(urlObj){ location.href = urlObj.val(); }else{ location.reload(); } } } else { $.dialog.alert(data.msg); btnObj.prop("disabled", false); btnObj.val("再次提交"); } } //表单提交出错 function formError(XMLHttpRequest, textStatus, errorThrown) { $.dialog.alert("状态:" + textStatus + ";出错提示:" + errorThrown); btnObj.prop("disabled", false); btnObj.val("再次提交"); } } /*显示AJAX分页列表*/ function AjaxPageList(listDiv, pageDiv, pageSize, pageCount, sendUrl, defaultAvatar) { //pageIndex -页面索引初始值 //pageSize -每页显示条数初始化 //pageCount -取得总页数 InitComment(0);//初始化评论数据 $(pageDiv).pagination(pageCount, { callback: pageselectCallback, prev_text: "« 上一页", next_text: "下一页 »", items_per_page:pageSize, num_display_entries:3, current_page:0, num_edge_entries:5, link_to:"javascript:;" }); //分页点击事件 function pageselectCallback(page_id, jq) { InitComment(page_id); } //请求评论数据 function InitComment(page_id) { page_id++; $.ajax({ type: "POST", dataType: "json", url: sendUrl + "&page_size=" + pageSize + "&page_index=" + page_id, beforeSend: function (XMLHttpRequest) { $(listDiv).html('

正在很努力加载,请稍候...

'); }, success: function(data) { //$(listDiv).html(data); var strHtml = ''; for(var i in data){ strHtml += '
  • ' + '
    #' + (parseInt(parseInt(i) + 1) + parseInt(pageSize) * parseInt(page_id-1)) + '
    ' + '
    '; if(typeof(data[i].avatar) != "undefined"){ strHtml += ''; }else{ strHtml += ''; } strHtml += '
    ' + '
    ' + '

    ' + unescape(data[i].content) + '

    ' + '
    ' + '' + data[i].user_name + '\n' + '' + data[i].add_time + '' + '
    ' + '
    '; if(data[i].is_reply == 1){ strHtml += '
    ' + '
    ' + '' + data[i].reply_time + '' + '管理员回复:' + '
    ' + '

    ' + unescape(data[i].reply_content) + '

    ' + '
    '; } strHtml += '
  • '; } $(listDiv).html(strHtml); }, error: function (XMLHttpRequest, textStatus, errorThrown) { $(listDiv).html('

    暂无评论,快来抢沙发吧!

    '); } }); } }