var _commonfunc = { showmsgbox: function() { }, jsontodatetime: function(date) { }, jsontodate: function(date) { }, jsontotime: function(date) { } }; _commonfunc.jsontotime = function(date) { var da = new date(parseint(date.replace("/date(", "").replace(")/", "").split("+")[0])); return da.gethours() + ":" + da.getseconds(); //+ ":" + da.getminutes(); } _commonfunc.jsontodate = function(data) { var da = new date(parseint(date.replace("/date(", "").replace(")/", "").split("+")[0])); return da.getfullyear() + "" + (da.getmonth() + 1) + "-" + da.getdate(); } _commonfunc.jsontodatetime = function(date) { var da = new date(parseint(date.replace("/date(", "").replace(")/", "").split("+")[0])); return da.getfullyear() + "-" + (da.getmonth() + 1) + "-" + da.getdate() + " " + da.gethours() + ":" + da.getseconds(); //+ ":" + da.getminutes(); } //## _commonfunc.showmsgbox = function(msg, options) _commonfunc.showmsgbox = function(msg, options) { //设置参数 var defaults = { title: "中国陶瓷官网", width: 300, height: 180, textalign: "center", buttonalign: "center", //center left right showyesbutton: true, showcancelbutton: false, yeshandel: function() { }, cancelhandel: function() { } }; var settings = $.extend({}, defaults, options); //产生 div var dia = $("#_msgbox"); if (dia.length == 0) { dia = $('

'); dia.appendto('body'); } //显示提示框 var p = dia.find("p").html(msg); p.css("text-align", settings.textalign); var buttons = {}; //yes if (settings.showyesbutton == true) //如果现实 { buttons.确定 = function() { settings.yeshandel(); //运行设置的句柄 //清除元素 $(this).dialog("destroy"); //删除 juery dia.remove(); //删除 元素 } } //cancel if (settings.showcancelbutton == true) //如果现实 { buttons.取消 = function() { settings.cancelhandel(); //运行设置的句柄 //清除元素 $(this).dialog("destroy"); //删除 juery dia.remove(); //删除 元素 } } var diasettings = { resizable: false, modal: true, title: settings.title, width: settings.width, height: settings.height, autoopen: false, //不是自动运行 buttons: buttons }; dia.dialog(diasettings); //设置按钮位置方向 var div1 = dia.parent().find(".ui-dialog-buttonpane"); div1.css("text-align", settings.buttonalign); var buttondiv = dia.parent().find(".ui-dialog-buttonset"); buttondiv.css("float", settings.buttonalign); //--------------------------------------- dia.dialog("open"); }; //#end //## function autoresizeimage( width, height,obj) { function autoresizeimage(width, height, obj) { //定义要限制的图片宽高,这个宽高要同style里面定义的相同,小于限定高宽的图片不操作 var image = $(obj); if(image.width() > width) { image.height(width / image.width() * image.height()); image.width(width); } if(image.height() > height) { image.width(height / image.height() * image.width()); image.height(height); } if(image.height() > 0 && image.height() < height) { image.css("paddingtop", (height - image.height()) / 2 + "px"); image.css("paddingbottom", (height - image.height()) / 2 + "px"); } }; //段胜利 //长宽等比 //横图上下加空白 //竖图左右加空白 //小图进行等比放大,大图等比缩小 //因为这个函数式 onload中使用。 所以当没有图片时,不会运行 //使用方法: function resizeimage(_this) { //获取图片的原始尺寸 var image = new image(); //创建一个新图片 image.src = $(_this).attr("src"); var _origwidth = image.width-0; var _origheight = image.height-0; //删除图片 image = null; //获取当前图片设置的尺寸 var width = $(_this).width()-0; var height = $(_this).height()-0; //查看缩放比例,来决定是横图还是竖图 var zoomw = width / _origwidth; var zoomh = height / _origheight; //横图 增加上下空白 // margin padding //if (_origwidth > _origheight) if (zoomw < zoomh) //显示横图 { var pad1 = 0; if ($(_this).css("padding-top")) { pad1 = $(_this).css("padding-top").replace("px", "") - 0; } var pad2 = 0; if ($(_this).css("padding-bottom")) { pad2 = $(_this).css("padding-bottom").replace("px", "") - 0; } var newheight = _origheight * (width / _origwidth); var marg = (height - newheight) / 2; $(_this).height(newheight); $(_this).css("padding-top", marg + pad1 + "px"); $(_this).css("padding-bottom", marg + pad2 + "px"); } else { //获取padding值 var pad1 = 0; if ($(_this).css("padding-left")) { pad1 = $(_this).css("padding-left").replace("px","")-0; } var pad2 = 0; if ($(_this).css("padding-right")) { pad2 = $(_this).css("padding-right").replace("px","")-0; } var newwidth = _origwidth * (height / _origheight); var marg = (width - newwidth) / 2 ; $(_this).width(newwidth); $(_this).css("padding-left", marg + pad1+"px"); $(_this).css("padding-right", marg + pad2+"px"); } } function substring(str,leng) { if (str != null && str.length > 0) { var str2 = str.substring(0, leng); if (str2 != str) { str2 = str2 + "..."; } return str2; } else { return str; } } function percentsizeimage(perwidth, perheight, obj) { //定义要限制的图片宽高,这个宽高要同style里面定义的相同,小于限定高宽的图片不操作 var width = screen.width * perwidth*0.01; //var height = screen.height * perheight * 0.01; var height = screen.width * perwidth * 0.01; // var height = width; var image = $(obj); // image.height(1); if (image.width() > width) { image.height(width / image.width() * image.height()); image.width(width); } if (image.height() > height) { image.width(height / image.height() * image.width()); image.height(height); } if (image.height() > 0 && image.height() < height) { image.css("paddingtop", (height - image.height()) / 2 + "px"); image.css("paddingbottom", (height - image.height()) / 2 + "px"); } }; //宽是百分比,高随意 //function percentsizeimage(perwidth, perheight, obj) { // //定义要限制的图片宽高,这个宽高要同style里面定义的相同,小于限定高宽的图片不操作 // var width = screen.width * perwidth * 0.01; // var height = screen.height * perheight * 0.01; // var image = $(obj); // if (image.width() > width) { // image.height(width / image.width() * image.height()); // image.width(width); // } //}; //#end //## function showmsgbox(text) 显示消息提示框 ,页面中需有隐藏的div function showmsgbox(text) { var dia = $("#dialog-message"); dia.find("p").text(text); dia.dialog( { resizable : false, modal: true, // title:"中国陶瓷官网", // width: "600", // height: "400", // autoopen: false, buttons : { "确定" : function() { $(this).dialog("close"); } } }); }; // // // // //#end //## function isnumber(strid) 判断是不是正整数 function isnumber(strid) { var strp = /^\d+$/; //正整数 //正则表达式,真好用 , return strp.test($('#' + strid).val()); //返回 false 或者 true }; //#end //## regexpverify 正则表达式 判断 //注意:不能使用regexp名字,否则冲突 var regexpverify = { email: function() { }, number: function() { }, telephone:function(){} }; regexpverify.number = function(str) { var strp = /^\d+$/; //正整数 //正则表达式,真好用 , return strp.test(str); }; regexpverify.email = function(email) { var re = /\w+@\w+\.\w+/; if (re.test(email)) return true; else return false; }; regexpverify.telephone = function(str) { var reg = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/; var isvalid isvalid = reg.exec(str) if (!isvalid) { return false } return true }; //#end function formatdate(dt) { var year = dt.getfullyear(); var month = dt.getmonth() + 1; var date = dt.getdate(); if (month < 10) { month = "0" + month; } if (date < 10) { date = "0" + date; } return year + "-" + month + "-" + date; } function testit(dt) { var dtime = dt; var newdtime = new date(parseint(dtime.slice(6, 21))); return formatdate(newdtime); } function delhtmltag(str) { return str.replace(/<[^>]+>/g, ""); //去掉所有的html标记 } function getback() { history.go(-1); } function cciasubstring(str, num) { if (str && (getstrlength(str)) > (num * 2)) { var str2 = str.substring(0, num * 2); if (str != str2) { str = str2 + "..."; } return str; } else { return str; } } // function getstrlength(str) { var carr = str.match(/[^\x00-\xff]/ig); return str.length + (carr == null ? 0 : carr.length); } //图片上传预览 ie是用了滤镜。 function previewimage(file) { var maxwidth = 260; var maxheight = 180; var div = document.getelementbyid('preview'); if (file.files && file.files[0]) { div.innerhtml = ''; var img = document.getelementbyid('imghead'); img.onload = function() { var rect = clacimgzoomparam(maxwidth, maxheight, img.offsetwidth, img.offsetheight); img.width = rect.width; img.height = rect.height; // img.style.marginleft = rect.left+'px'; img.style.margintop = rect.top + 'px'; } var reader = new filereader(); reader.onload = function(evt) { img.src = evt.target.result; } reader.readasdataurl(file.files[0]); } else //兼容ie { var sfilter = 'filter:progid:dximagetransform.microsoft.alphaimageloader(sizingmethod=scale,src="'; file.select(); var src = document.selection.createrange().text; div.innerhtml = ''; var img = document.getelementbyid('imghead'); img.filters.item('dximagetransform.microsoft.alphaimageloader').src = src; var rect = clacimgzoomparam(maxwidth, maxheight, img.offsetwidth, img.offsetheight); status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width + ',' + rect.height); div.innerhtml = "
"; } } function clacimgzoomparam(maxwidth, maxheight, width, height) { var param = { top: 0, left: 0, width: width, height: height }; if (width > maxwidth || height > maxheight) { ratewidth = width / maxwidth; rateheight = height / maxheight; if (ratewidth > rateheight) { param.width = maxwidth; param.height = math.round(height / ratewidth); } else { param.width = math.round(width / rateheight); param.height = maxheight; } } param.left = math.round((maxwidth - param.width) / 2); param.top = math.round((maxheight - param.height) / 2); return param; }