//添加方法 String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.lTrim = function () { return this.replace(/(^\s*)/g, ""); } String.prototype.rTrim = function () { return this.replace(/(\s*$)/g, ""); } String.prototype.realLength = function () { return this.replace(/[^\x00-\xff]/g, "**").length; } String.prototype.realSubString = function (realLen) { if (!realLen) { return ''; } //预期计数:中文2字节,英文1字节 var a = 0; //循环计数 var i = 0; //临时字串 var temp = ''; for (i = 0; i < this.length; i++) { if (this.charCodeAt(i) > 255) { //按照预期计数增加2 a += 2; } else { a++; } //如果增加计数后长度大于限定长度,就直接返回临时字符串 if (a > realLen) { return temp; } //将当前内容加到临时字符串 temp += this.charAt(i); } //如果全部是单字节字符,就直接返回源字符串 return this; } //工具 var Tools = new Object(); ////$(function() { //禁止网页中的所有 form的submit提交 // alert($("form[action='']").length); $("form[action='']").submit(function () { return false; }) //自动为密码框添加全选 $("[type=password]").bind("focus", function () { this.select(); }) //给textarea添加maxlenght方法 $("textarea").bind("keyup", function () { var mlength = this.getAttribute ? parseInt(this.getAttribute("maxlength")) : ""; if (this.getAttribute && this.value.realLength() > mlength) { this.value = this.value.realSubString(mlength) alert("字符超出限制长度{0},一个中文占用两个字符!".replace('{0}', mlength)); } }) //添加textArea的长度显示 $.each($("textarea"), function (i, item) { var mlength = item.getAttribute ? parseInt(item.getAttribute("maxlength")) : ""; if (item.getAttribute) { var mlengthMsg = "最多可输入{0}个字符!".replace('{0}', mlength); item.title = item.title + " " + mlengthMsg; item.title = item.title.trim(); } }); //给所有有默认显示图片的img控件加了默认图片地址 $.each($("img.default-image"), function (i, img) { var src = img.src; img.defaultSrc = src; //添加defaultSrc $(img).bind("error", function () { //alert("error" + this.src); this.src = this.defaultSrc; }).bind("load", function () { //alert("load" + this.src); }); }); $.each($(".delete-image"), function (i, item) { if ($(this).siblings("input").val().length != 0) { $(this).removeClass("hidden"); } }) $(".delete-image").bind("click", function () { //取消数据 $(this).siblings("input").val(""); //取消图片 $.each($(this).siblings("img"), function (i, item) { //不显示自己 if (typeof (item.defaultSrc) != "undefined") { item.src = item.defaultSrc; } else { item.src = ""; } }); $(this).addClass("hidden"); return false; }); //限定图片显示大小 $(".default-image").bind("load", function () { if (this.height > 200) { this.height = 200; } }) //文件上传定义 $.each($(".delete-file"), function (i, item) { if ($(this).siblings("input").val().length != 0) { $(this).removeClass("hidden"); } }) $.each($(".download-file"), function (i, item) { if ($(this).siblings("input").val().length != 0) { $(this).removeClass("hidden"); } }) $(".delete-file").bind("click", function () { //取消数据 $(this).siblings("input").val(""); $(this).siblings(".download-file").addClass("hidden"); $(this).addClass("hidden"); return false; }); //选择框 $(".select-clear").bind("click", function () { //取消数据 $(this).siblings("input").val(""); $(this).addClass("hidden"); //触发验证 $(this).siblings("input").focus(); $(this).siblings("input").blur(); return false; }); //初始的时候判断当前是否已经有数据有的话显示 $.each($(".select-clear"), function (i, item) { if ($(this).siblings("input").val().length != 0) { $(this).removeClass("hidden"); } }) function YKPage(json) { //取得分页对像 var first = document.getElementById("pageFirst"); var prev = document.getElementById("pagePrev"); var next = document.getElementById("pageNext"); var last = document.getElementById("pageLast"); var select = document.getElementById("pageList"); var record = document.getElementById("pageRecord"); var color = "#999999"; //赋值新的页数 $("#frmQuery [name=PageIndex]").attr("value", json.PageIndex); //页数 record.innerHTML = json.RecordCount; if (json.RecordCount == 0) { first.style.color = prev.style.color = next.style.color = last.style.color = color; first.href = prev.href = next.href = last.href = "#page=0"; first.onclick = function () { return false; }; prev.onclick = function () { return false; }; next.onclick = function () { return false; }; last.onclick = function () { return false; }; select.length = 0; var option_node = new Option("0 / 0", "0"); select.options.add(option_node); return; } //判断是否首页有效 first.href = "#page=first"; if (json.PageIndex == 1) { first.style.color = color; first.onclick = function () { return false; } } else { first.style.color = ""; first.onclick = function () { $("#frmQuery [name=PageIndex]").attr("value", 1); Search(); return false; } } //末页 last.href = "#page=last"; if (json.PageIndex == json.PageCount) { last.style.color = color; last.onclick = function () { return false; } } else { last.style.color = ""; last.onclick = function () { $("#frmQuery [name=PageIndex]").attr("value", json.PageCount); Search(); return false; } } //上一页 prev.href = "#page=" + (json.PageIndex - 1 < 1 ? 1 : json.PageIndex - 1); ; if (json.PageIndex == 1) { prev.style.color = color; prev.onclick = function () { return false; } } else { prev.style.color = ""; prev.onclick = function () { $("#frmQuery [name=PageIndex]").attr("value", json.PageIndex - 1); Search(); return false; } } //下一页 next.href = "#page=" + (json.PageIndex + 1 > json.PageCount ? json.PageCount : json.PageIndex + 1); if (json.PageIndex == json.PageCount) { next.style.color = color; next.onclick = function () { return false; } } else { next.style.color = ""; next.onclick = function () { $("#frmQuery [name=PageIndex]").attr("value", json.PageIndex + 1); Search(); return false; } } //下拉 select.length = 0; for (var i = 1; i <= json.PageCount; i++) { var option_node = new Option(); option_node.text = i + " / " + json.PageCount; option_node.value = i; //如果为当前时 if (i == json.PageIndex) { option_node.selected = true; } select.options.add(option_node); } select.onchange = function () { $("#frmQuery [name=PageIndex]").attr("value", this.value); Search(); } }; //去列表 function GoList(param) { var url = "list.aspx" if (typeof (param) != "undefined") { url += "?" + param; } window.location.href = url; return false; } //返回 function GoReturn() { //window.location.href = document.referrer; window.history.back(); return false; }; //跳转页面 function GoUrl(url) { window.location.href = url; return false; } function GoAdd(param) { var url = "edit.aspx"; if (typeof (param) != "undefined") { url += "?" + param; } window.location.href = url; return false; }; //标签开关 function SwitchTag(obj) { var tag = $(obj).next("div").next("div"); if (tag.css("display") == "none") { $(tag).slideDown(); $(obj).find("b").removeClass("Bclded").addClass("Bopned"); } else { $(tag).slideUp(); $(obj).find("b").removeClass("Bopned").addClass("Bclded"); } }; //对话框选择 function Select(valuevalue, namevalue, temp1value, temp2value, temp3value) { $(window.parent.window.document).find(valueControl).val(valuevalue); $(window.parent.window.document).find(nameControl).val(namevalue); if (typeof (temp1value) != "undefined" && typeof (temp1valueControl) != "undefined") { $(window.parent.window.document).find(temp1valueControl).val(temp1value); } if (typeof (temp2value) != "undefined" && typeof (temp2valueControl) != "undefined") { $(window.parent.window.document).find(temp2valueControl).val(temp2value); } if (typeof (temp3value) != "undefined" && typeof (temp3valueControl) != "undefined") { $(window.parent.window.document).find(temp2valueControl).val(temp3value); } //显示清除 $(window.parent.window.document).find(valueControl).siblings(".select-clear").removeClass("hidden"); $(window.parent.window.document).find(nameControl).focus(); window.parent.window.$.fn.fancybox.close(); } //文件上传 function UploadFile(valueControl, title, type, path, fileName, width, height,sizeControl) { $.fn.fancybox.show({ 'zoomSpeedIn': 600, 'zoomSpeedOut': 500, frameWidth: 500, frameHeight: 350, frameURL: Global.Site + "/tools/uploadform.aspx?title=" + encodeURIComponent(title) + "&type=" + encodeURIComponent(type) + "&path=" + encodeURIComponent(path) + "&fileName=" + encodeURIComponent(fileName) + "&height=" + encodeURIComponent(height) + "&width=" + encodeURIComponent(width) + "&valueControl=" + encodeURIComponent(valueControl) + "&sizeControl=" + encodeURIComponent(sizeControl), hideOnContentClick: false }); return false; } //按钮样式管理 $(".btn-dft-gc").bind("mouseup", function () { $(this).removeClass("btn-dft-gc-active").addClass("btn-dft-gc-hover"); }).bind("mousedown", function () { $(this).removeClass("btn-dft-gc-hover").addClass("btn-dft-gc-active"); }).bind("mouseover", function () { $(this).removeClass("btn-dft-gc-active").addClass("btn-dft-gc-hover"); }).bind("mouseout", function () { $(this).removeClass("btn-dft-gc-hover btn-dft-gc-active"); }); $(".btn-dft-gl").bind("mouseup", function () { $(this).removeClass("btn-dft-gl-active").addClass("btn-dft-gl-hover"); }).bind("mousedown", function () { $(this).removeClass("btn-dft-gl-hover").addClass("btn-dft-gl-active"); }).bind("mouseover", function () { $(this).removeClass("btn-dft-gl-active").addClass("btn-dft-gl-hover"); }).bind("mouseout", function () { $(this).removeClass("btn-dft-gl-hover btn-dft-gl-active"); }); $(".btn-dft-gr").bind("mouseup", function () { $(this).removeClass("btn-dft-gr-active").addClass("btn-dft-gr-hover"); }).bind("mousedown", function () { $(this).removeClass("btn-dft-gr-hover").addClass("btn-dft-gr-active"); }).bind("mouseover", function () { $(this).removeClass("btn-dft-gr-active").addClass("btn-dft-gr-hover"); }).bind("mouseout", function () { $(this).removeClass("btn-dft-gr-hover btn-dft-gr-active"); }); $(".btn-dft-impt").bind("mouseup", function () { $(this).removeClass("btn-dft-impt-active").addClass("btn-dft-impt-hover"); }).bind("mousedown", function () { $(this).removeClass("btn-dft-impt-hover").addClass("btn-dft-impt-active"); }).bind("mouseover", function () { $(this).removeClass("btn-dft-impt-active").addClass("btn-dft-impt-hover"); }).bind("mouseout", function () { $(this).removeClass("btn-dft-impt-hover btn-dft-impt-active"); }); $(".btn-dft-icon").bind("mouseup", function () { $(this).removeClass("btn-dft-icon-active").addClass("btn-dft-icon-hover"); }).bind("mousedown", function () { $(this).removeClass("btn-dft-icon-hover").addClass("btn-dft-icon-active"); }).bind("mouseover", function () { $(this).removeClass("btn-dft-icon-active").addClass("btn-dft-icon-hover"); }).bind("mouseout", function () { $(this).removeClass("btn-dft-icon-hover btn-dft-icon-active"); }); $(".btn-dft").not(".btn-dft-gc ").not(".btn-dft-gl ").not(".btn-dft-gr ").not(".btn-dft-icon ").bind("mouseup", function () { $(this).removeClass("btn-dft-active").addClass("btn-dft-hover"); }).bind("mousedown", function () { $(this).removeClass("btn-dft-hover").addClass("btn-dft-active"); }).bind("mouseover", function () { $(this).removeClass("btn-dft-active").addClass("btn-dft-hover"); }).bind("mouseout", function () { $(this).removeClass("btn-dft-hover btn-dft-active"); }); $(".ipt-t.ipt-t-dft").bind("focus", function () { $(this).addClass("ipt-t-dft-active"); }).bind("blur", function () { $(this).removeClass("ipt-t-dft-active"); }) //格式化编辑器 $(function () { if ($.xheditor) { $("textarea.xheditor").xheditor({ tools: "mini" }); $("textarea.xheditor-mini").xheditor({ tools: "mini" }); $("textarea.xheditor-simple").xheditor({ tools: "simple" }) $('textarea.xheditor-full').xheditor({ tools: "full", upLinkUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upLinkExt: "zip,rar,txt,7z", upImgUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upImgExt: "jpg,jpeg,gif", upFlashUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upFlashExt: "swf", upMediaUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upMediaExt: "avi,asf,wmv,mp4" }) $('textarea.xheditor-edit').xheditor({ tools: "full", upLinkUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upLinkExt: "zip,rar,txt,7z", upImgUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upImgExt: "jpg,jpeg,gif", upFlashUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upFlashExt: "swf", upMediaUrl: Global.Site + "/js/zh-cn/XhEditor/upload.aspx", upMediaExt: "avi,asf,wmv,mp4" }) } }); $(".gWel-tab .tabs li").each(function (i) { $(this).bind("click", function () { //如果当前没有class on的时候将父级的li的class on去除 if (!$(this).hasClass("on")) { $(this).parents("ul").find("li").removeClass("on") $(this).addClass("on"); //显示对应的div var panel = $(this).parents(".gWel-tab").find(".pans .panel"); panel.hide(); var ifrm = panel.eq(i).find(".ifrmtab"); if (ifrm.length > 0) { // if (ifrm[0].src == null || ifrm[0].src == "" || ifrm[0].src == ifrm[0].title) { // ifrm[0].src = ifrm[0].title; // } ifrm[0].src = ifrm[0].title; //计算IFrame高度 ifrm.height($("#divMain").height() - 80); } panel.eq(i).show(); } }); }); //如果有指定显示的话显示他 var panelTab = $.url.param("panel") if (typeof (panelTab) != "undefined") { $(".gWel-tab .tabs li").eq(panelTab).click(); } else { if ($(".gWel-tab .tabs li").length > 0) { $(".gWel-tab .tabs li").eq(0).click(); } } $(function () { //初始方法 //以下为生成提示 if ($.tipsy) { $(".tooltip").tipsy({ fade: true }); } if ($.datepicker) { $(".date").live("focus", function () { $(this).datepicker(); }); } if ($.datepicker) { $(".datetime").live("focus", function () { $(this).datetimepicker(); }); } if ($.timepicker) { $(".time").live("focus", function () { $(this).timepicker({}); }); } });