// 布局脚本 /*==================================== *基于jquery 1.9.0主框架 *vlcms管理界面 *作者:一些事情 ====================================*/ //绑定需要浮动的表头 $(function(){ $(".ltable tr:nth-child(odd)").addclass("odd_bg"); //隔行变色 $("#floathead").smartfloat(); $(".rule-single-checkbox").rulesinglecheckbox(); $(".rule-multi-checkbox").rulemulticheckbox(); $(".rule-multi-radio").rulemultiradio(); $(".rule-single-select").rulesingleselect(); $(".rule-multi-porp").rulemultiporp(); }); //全选取消按钮函数 function checkall(chkobj) { if ($(chkobj).text() == "全选") { $(chkobj).children("span").text("取消"); $(".checkall input:enabled").prop("checked", true); } else { $(chkobj).children("span").text("全选"); $(".checkall input:enabled").prop("checked", false); } } //tab控制函数 function tabs(tabobj) { var tabnum = $(tabobj).parent().index("li") //设置点击后的切换样式 $(tabobj).parent().parent().find("li a").removeclass("selected"); $(tabobj).addclass("selected"); //根据参数决定显示内容 $(".tab-content").hide(); $(".tab-content").eq(tabnum).show(); } //===========================工具类函数============================ //只允许输入数字 function checknumber(e) { if (isfirefox = navigator.useragent.indexof("firefox") > 0) { //ff if (!((e.which >= 48 && e.which <= 57) || (e.which >= 96 && e.which <= 105) || (e.which == 8) || (e.which == 46))) return false; } else { if (!((event.keycode >= 48 && event.keycode <= 57) || (event.keycode >= 96 && event.keycode <= 105) || (event.keycode == 8) || (event.keycode == 46))) event.returnvalue = false; } } //检查短信字数 function checktxt(obj, txtid) { var txtcount = $(obj).val().length; if (txtcount < 1) { return false; } var smslength = math.ceil(txtcount / 62); $("#" + txtid).html("您已输入" + txtcount + "个字符,将以" + smslength + "条短信扣取费用。"); } //检查短信字数 function checktxt2(obj, txtid) { var txtcount = $(obj).val().length; if (txtcount < 1) { return false; } var smslength = math.ceil(txtcount / 62); $("#" + txtid).html("您已输入" + txtcount + "个字符"); } //四舍五入函数 function fordight(dight, how) { dight = math.round(dight * math.pow(10, how)) / math.pow(10, how); return dight; } //写cookie function addcookie(objname, objvalue, objhours) { var str = objname + "=" + escape(objvalue); if (objhours > 0) {//为0时不设定过期时间,浏览器关闭时cookie自动消失 var date = new date(); var ms = objhours * 3600 * 1000; date.settime(date.gettime() + ms); str += "; expires=" + date.togmtstring(); } document.cookie = str; } //读cookie function getcookie(objname) {//获取指定名称的cookie的值 var arrstr = document.cookie.split("; "); for (var i = 0; i < arrstr.length; i++) { var temp = arrstr[i].split("="); if (temp[0] == objname) return unescape(temp[1]); } return ""; } //========================基于lhgdialog插件======================== //可以自动关闭的提示,基于lhgdialog插件 function jsprint(msgtitle, url, msgcss, callback) { var iconurl = ""; switch (msgcss) { case "success": iconurl = "32x32/succ.png"; break; case "error": iconurl = "32x32/fail.png"; break; default: iconurl = "32x32/hits.png"; break; } $.dialog.tips(msgtitle, 2, iconurl); if (url == "back") { frames["mainframe"].history.back(-1); } else if (url != "") { frames["mainframe"].location.href = url; } //执行回调函数 if (arguments.length == 4) { callback(); } } //弹出一个dialog窗口 function jsdialog(msgtitle, msgcontent, url, msgcss, callback) { var iconurl = ""; var argnum = arguments.length; switch (msgcss) { case "success": iconurl = "success.gif"; break; case "error": iconurl = "error.gif"; break; default: iconurl = "alert.gif"; break; } var dialog = $.dialog({ title: msgtitle, content: msgcontent, fixed: true, min: false, max: false, lock: true, icon: iconurl, ok: true, close: function () { if (url == "back") { history.back(-1); } else if (url != "") { location.href = url; } //执行回调函数 if (argnum == 5) { callback(); } } }); } //打开一个最大化的dialog function showmaxdialog(tit, url) { $.dialog({ title: tit, content: 'url:' + url, min: false, max: false, lock: false }).max(); } //执行回传函数 function exepostback(objid, objmsg) { if ($(".checkall input:checked").size() < 1) { $.dialog.alert('对不起,请选中您要操作的记录!'); return false; } var msg = "删除记录后不可恢复,您确定吗?"; if (arguments.length == 2) { msg = objmsg; } $.dialog.confirm(msg, function () { __dopostback(objid, ''); }); return false; } //检查是否有选中再决定回传 function checkpostback(objid, objmsg) { var msg = "对不起,请选中您要操作的记录!"; if (arguments.length == 2) { msg = objmsg; } if ($(".checkall input:checked").size() < 1) { $.dialog.alert(msg); return false; } __dopostback(objid, ''); return false; } //执行回传无复选框确认函数 function exenocheckpostback(objid, objmsg) { var msg = "删除记录后不可恢复,您确定吗?"; if (arguments.length == 2) { msg = objmsg; } $.dialog.confirm(msg, function () { __dopostback(objid, ''); }); return false; } //执行回传无复选框确认函数 function exenocheckpostback2(objid, objmsg,url) { var msg = "删除记录后不可恢复,您确定吗?"; if (arguments.length == 2) { msg = objmsg; } $.dialog.confirm(msg, function () { $.ajax({ url: url, data: { id: objid,action: "delete" }, success: function (obj) { if (obj == "ok") { parent.jsprint("删除成功","/admin/settings/area_list.aspx","success"); } else { $.dialog.alert(obj); } } }); }); return false; } //======================以上基于lhgdialog插件====================== //========================基于validform插件======================== //初始化验证表单 $.fn.initvalidform = function () { var checkvalidform = function (formobj) { $(formobj).validform({ tiptype: function (msg, o, cssctl) { /*msg:提示信息; o:{obj:*,type:*,curform:*} obj指向的是当前验证的表单元素(或表单对象); type指示提示的状态,值为1、2、3、4, 1:正在检测/提交数据,2:通过验证,3:验证失败,4:提示ignore状态; curform为当前form对象; cssctl:内置的提示信息样式控制函数,该函数需传入两个参数:显示提示信息的对象 和 当前提示的状态(既形参o中的type);*/ //全部验证通过提交表单时o.obj为该表单对象; if (!o.obj.is("form")) { //定位到相应的tab页面 if (o.obj.is(o.curform.find(".validform_error:first"))) { var tabobj = o.obj.parents(".tab-content"); //显示当前的选项 var tabindex = $(".tab-content").index(tabobj); //显示当前选项索引 if (!$(".content-tab ul li").eq(tabindex).children("a").hasclass("selected")) { $(".content-tab ul li a").removeclass("selected"); $(".content-tab ul li").eq(tabindex).children("a").addclass("selected"); $(".tab-content").hide(); tabobj.show(); } } //页面上不存在提示信息的标签时,自动创建; if (o.obj.parents("dd").find(".validform_checktip").length == 0) { o.obj.parents("dd").append(""); o.obj.parents("dd").next().find(".validform_checktip").remove(); } var objtip = o.obj.parents("dd").find(".validform_checktip"); cssctl(objtip, o.type); objtip.text(msg); } }, showallerror: true }); }; return $(this).each(function () { checkvalidform($(this)); }); } //======================以上基于validform插件====================== //智能浮动层函数 $.fn.smartfloat = function() { var position = function(element) { var top = element.position().top; var pos = element.css("position"); $(window).scroll(function() { var scrolls = $(this).scrolltop(); if (scrolls > top) { if (window.xmlhttprequest) { element.css({ position: "fixed", top: 0 }); } else { element.css({ top: scrolls }); } }else { element.css({ position: pos, top: top }); } }); }; return $(this).each(function() { position($(this)); }); }; //复选框 $.fn.rulesinglecheckbox = function () { var singlecheckbox = function (parentobj) { //查找复选框 var checkobj = parentobj.children('input:checkbox').eq(0); parentobj.children().hide(); //添加元素及样式 var newobj = $('' + '' + '' + '').prependto(parentobj); parentobj.addclass("single-checkbox"); //判断是否选中 if (checkobj.prop("checked") == true) { newobj.addclass("selected"); } //检查控件是否启用 if(checkobj.prop("disabled") == true){ newobj.css("cursor","default"); return; } //绑定事件 $(newobj).click(function () { if ($(this).hasclass("selected")) { $(this).removeclass("selected"); //checkobj.prop("checked", false); } else { $(this).addclass("selected"); //checkobj.prop("checked", true); } checkobj.trigger("click"); //触发对应的checkbox的click事件 }); }; return $(this).each(function () { singlecheckbox($(this)); }); }; //多项复选框 $.fn.rulemulticheckbox = function() { var multicheckbox = function(parentobj){ parentobj.addclass("multi-checkbox"); //添加样式 parentobj.children().hide(); //隐藏内容 var divobj = $('
').prependto(parentobj); //前插入一个div parentobj.find(":checkbox").each(function(){ var indexnum = parentobj.find(":checkbox").index(this); //当前索引 var newobj = $('' + parentobj.find('label').eq(indexnum).text() + '').appendto(divobj); //查找对应label创建选项 if($(this).prop("checked") == true){ newobj.addclass("selected"); //默认选中 } //检查控件是否启用 if($(this).prop("disabled") == true){ newobj.css("cursor","default"); return; } //绑定事件 $(newobj).click(function(){ if($(this).hasclass("selected")){ $(this).removeclass("selected"); //parentobj.find(':checkbox').eq(indexnum).prop("checked",false); }else{ $(this).addclass("selected"); //parentobj.find(':checkbox').eq(indexnum).prop("checked",true); } parentobj.find(':checkbox').eq(indexnum).trigger("click"); //触发对应的checkbox的click事件 //alert(parentobj.find(':checkbox').eq(indexnum).prop("checked")); }); }); }; return $(this).each(function() { multicheckbox($(this)); }); } //多项选项prop $.fn.rulemultiporp = function() { var multiporp = function(parentobj){ parentobj.addclass("multi-porp"); //添加样式 parentobj.children().hide(); //隐藏内容 var divobj = $('').prependto(parentobj); //前插入一个div parentobj.find(":checkbox").each(function(){ var indexnum = parentobj.find(":checkbox").index(this); //当前索引 var liobj = $('
  • ').appendto(divobj) var newobj = $('' + parentobj.find('label').eq(indexnum).text() + '').appendto(liobj); //查找对应label创建选项 if($(this).prop("checked") == true){ liobj.addclass("selected"); //默认选中 } //检查控件是否启用 if($(this).prop("disabled") == true){ newobj.css("cursor","default"); return; } //绑定事件 $(newobj).click(function(){ if($(this).parent().hasclass("selected")){ $(this).parent().removeclass("selected"); }else{ $(this).parent().addclass("selected"); } parentobj.find(':checkbox').eq(indexnum).trigger("click"); //触发对应的checkbox的click事件 //alert(parentobj.find(':checkbox').eq(indexnum).prop("checked")); }); }); }; return $(this).each(function() { multiporp($(this)); }); } //多项单选 $.fn.rulemultiradio = function() { var multiradio = function(parentobj){ parentobj.addclass("multi-radio"); //添加样式 parentobj.children().hide(); //隐藏内容 var divobj = $('
    ').prependto(parentobj); //前插入一个div parentobj.find('input[type="radio"]').each(function(){ var indexnum = parentobj.find('input[type="radio"]').index(this); //当前索引 var newobj = $('' + parentobj.find('label').eq(indexnum).text() + '').appendto(divobj); //查找对应label创建选项 if($(this).prop("checked") == true){ newobj.addclass("selected"); //默认选中 } //检查控件是否启用 if($(this).prop("disabled") == true){ newobj.css("cursor","default"); return; } //绑定事件 $(newobj).click(function(){ $(this).siblings().removeclass("selected"); $(this).addclass("selected"); parentobj.find('input[type="radio"]').prop("checked",false); parentobj.find('input[type="radio"]').eq(indexnum).prop("checked",true); parentobj.find('input[type="radio"]').eq(indexnum).trigger("click"); //触发对应的radio的click事件 //alert(parentobj.find('input[type="radio"]').eq(indexnum).prop("checked")); }); }); }; return $(this).each(function() { multiradio($(this)); }); } //单选下拉框 $.fn.rulesingleselect = function () { var singleselect = function (parentobj) { parentobj.addclass("single-select"); //添加样式 parentobj.children().hide(); //隐藏内容 var divobj = $('
    ').prependto(parentobj); //前插入一个div //创建元素 var titobj = $('').appendto(divobj); var itemobj = $('
    ').appendto(divobj); var arrowobj = $('').appendto(divobj); var selectobj = parentobj.find("select").eq(0); //取得select对象 //遍历option选项 selectobj.find("option").each(function (i) { var indexnum = selectobj.find("option").index(this); //当前索引 var liobj = $('
  • ' + $(this).text() + '
  • ').appendto(itemobj.find("ul")); //创建li if ($(this).prop("selected") == true) { liobj.addclass("selected"); titobj.find("span").text($(this).text()); } //检查控件是否启用 if ($(this).prop("disabled") == true) { liobj.css("cursor", "default"); return; } //绑定事件 liobj.click(function () { $(this).siblings().removeclass("selected"); $(this).addclass("selected"); //添加选中样式 selectobj.find("option").prop("selected", false); selectobj.find("option").eq(indexnum).prop("selected", true); //赋值给对应的option titobj.find("span").text($(this).text()); //赋值选中值 arrowobj.hide(); itemobj.hide(); //隐藏下拉框 selectobj.trigger("change"); //触发select的onchange事件 //alert(selectobj.find("option:selected").text()); }); }); //设置样式 //titobj.css({ "width": titobj.innerwidth(), "overflow": "hidden" }); //itemobj.children("ul").css({ "max-height": $(document).height() - titobj.offset().top - 62 }); //检查控件是否启用 if (selectobj.prop("disabled") == true) { titobj.css("cursor", "default"); return; } //绑定单击事件 titobj.click(function (e) { e.stoppropagation(); if (itemobj.is(":hidden")) { //隐藏其它的下位框菜单 $(".single-select .select-items").hide(); $(".single-select .arrow").hide(); //位于其它无素的上面 arrowobj.css("z-index", "1"); itemobj.css("z-index", "1"); //显示下拉框 arrowobj.show(); itemobj.show(); } else { //位于其它无素的上面 arrowobj.css("z-index", ""); itemobj.css("z-index", ""); //隐藏下拉框 arrowobj.hide(); itemobj.hide(); } }); //绑定页面点击事件 $(document).click(function (e) { selectobj.trigger("blur"); //触发select的onblure事件 arrowobj.hide(); itemobj.hide(); //隐藏下拉框 }); }; return $(this).each(function () { singleselect($(this)); }); }