/** * 表单转对象 * @returns object */ $.fn.serializeObject = function () { var o = {}; var a = this.serializeArray(); $.each(a, function () { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; } var req = {}; req.httpGet = function (url, params, callback, dataType) { dataType = dataType || 'json'; $.get(url, params, function (res) { if (res.code == 1001) { layer.msg('登录超时,请重新登录系统!!', function () { location.href = "/login?returnUrl=" + location.href; }); return; } callback(res); }, dataType); } req.httpPost = function (url, params, callback, dataType) { dataType = dataType || 'json'; $.post(url, params, function (res) { if (res.state == 1001) { layer.msg('登录超时,请重新登录系统!!', function () { location.href = "/login" + '?returnUrl=' + location.href; }); return; } callback(res); }, dataType); } req.getUrlParams = function (key) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); if (pair[0] == key) { return pair[1]; } } return (false); } function timekeeping(btn) { //把按钮设置为不可以点击 $(btn).attr("disabled", true).addClass("btn-disabled"); //每秒读取一次cookie var interval = setInterval(function () { //从cookie 中读取剩余倒计时 total = $.cookie("total"); //在发送按钮显示剩余倒计时 $(btn).text('请等待' + total + '秒'); // $('.getcode2').val('请等待' + total + '秒'); //把剩余总倒计时减掉1 total--; //剩余倒计时为零,则显示 重新发送,可点击 if (total == 0) { //清除定时器 clearInterval(interval); //删除cookie total = $.cookie("total", total, { expires: -1 }); //显示重新发送 $(btn).text('重新发送'); //把发送按钮设置为可点击 $(btn).removeAttr("disabled").removeClass("btn-disabled"); } else { //重新写入总倒计时 $.cookie("total", total); } }, 1000); }