/*
0:错误,1:正确,2:提示,3:加载中
showtip("11", 0); //错误
showtip("11", 1); //正确
showtip("11", 2); // 提示
showtip("11", 3); //加载中
msg, type, timeout, tp, gobackurl
msg:错误信息
type: 0:错误,1:正确,2:提示,3:加载中
timeout:延时时间
tp:距离top的像素
gobackurl:之后要跳转的页面,不指定则不跳转
*/
function showtip(msg) {
var type = 0, timeout = 2, tp = null;
if (arguments.length > 1) type = arguments[1];
if (arguments.length > 2) timeout = arguments[2];
if (arguments.length > 3) tp = arguments[3];
// if (arguments.length > 4) gobackurl = arguments[4];
// show(msg, type, timeout, tp, gobackurl);
show(msg, type, timeout, tp);
}
//_timer: null,
// show: function (msg, type, timeout, tp, gobackurl) {
function show(msg, type, timeout, tp) {
var _timer;
clearinterval(_timer);
var tip = '
{s}
'
var s = '{loadicon}{msghtml}';
var typeclass = { 0: "err", 1: "suc", 2: "info", 3: "clear" };
s = s.replace("{type}", typeclass[type]);
s = s.replace("{loadicon}", type == 3 ? '' : "");
s = s.replace("{msghtml}", msg);
tip = tip.replace("{s}", s);
var o = $("#msgtip");
if (o.length > 0) {
o.html(s);
} else {
$("body").append(tip);
}
o.css("left", (($(window).width() - o.width()) / 2) + "px").css("top", (($(window).height() - o.height()) / 2) + "px");
if (typeof (tp) == 'number') o.css("top", tp + "px");
o.show();
timeout = (typeof (timeout) == 'undefined') ? 1000 : timeout * 1000;
if (timeout) {
clearinterval(_timer);
_timer = setinterval(function () { hide(); }, timeout);
} else {
hide();
}
}
function hide() {
$("#msgtip").fadeout("slow");
}
//============================================================================
/*
参数说明:
msg:要显示的提示信息
obj:显示在此对象上面
type:显示样式
css样式定义在css/global.css中
xltip("请输入用户名!",$("#mobile"),2);
*/
function xltip(msg, obj, type) {
var typeclass = { 0: " ico_err", 1: " ico_suc", 2: " ico_info", 3: "" };
var textclass = { 0: " err_txt", 1: " suc_txt", 2: "", 3: "" };
tip = "";
$("body").append($(tip));
thisobj = obj; //显示在这个节点上
_t = thisobj.offset().top;
_left = thisobj.offset().left - 10;
_h = thisobj.outerheight();
_h2 = $('#xltip').outerheight();
_top = _t + _h;
if (_t < _h2) {
$('.tip_triangle_up', $('#xltip')).removeclass("tip_triangle_up").addclass("tip_triangle_down");
} else {
_top = _t - _h2;
}
$("#xltip").css({ top: _top, left: _left });
$(".tip_con_inner").html("" + msg + "");
$("#xltip").fadein();
timer = setinterval(function () {
clearinterval(timer);
$("#xltip").fadeout("fast", function () { $(this).remove(); });
}, 2000);
}
(function ($) {
$.fn.serializejson = function () {
var serializeobj = {};
var array = this.serializearray();
var str = this.serialize();
$(array).each(function () {
if (serializeobj[this.name]) {
if ($.isarray(serializeobj[this.name])) {
serializeobj[this.name].push(this.value);
} else {
serializeobj[this.name] = [serializeobj[this.name], this.value];
}
} else {
serializeobj[this.name] = this.value;
}
});
return serializeobj;
};
})(jquery);