前言

扩展自$.fn.datebox.defaults,使用$.fn.datetimebox.defaults重写默认值对象。下载该插件翻译源码

和日期输入框类似,日期时间输入框允许用户选择日期和指定的时间并按照指定的输出格式显示。相比日期输入框,它在下拉面板中添加了一个时间微调器。

源码

/**
* jQuery EasyUI 1.3.2
*
*翻译 qq 1364386878
*/
(function ($) {
//初始化方法
function init(jq) {
var datetimebox = $.data(jq, "datetimebox");
var options = datetimebox.options;
$(jq).datebox($.extend({}, options, {
onShowPanel: function () {
var value = $(jq).datetimebox("getValue");
_setValue(jq, value, true);
options.onShowPanel.call(jq);
},
formatter: $.fn.datebox.defaults.formatter,
parser: $.fn.datebox.defaults.parser
}));
$(jq).removeClass("datebox-f").addClass("datetimebox-f");
$(jq).datebox("calendar").calendar({
onSelect: function (value) {
options.onSelect.call(jq, value);
}
});
var panel = $(jq).datebox("panel");
if (!datetimebox.spinner) {
var p = $("<div style=\"padding:2px\"><input style=\"width:80px\"></div>").insertAfter(panel.children("div.datebox-calendar-inner"));
datetimebox.spinner = p.children("input");
var button = panel.children("div.datebox-button");
var ok = $("<a href=\"javascript:void(0)\" class=\"datebox-ok\"></a>").html(options.okText).appendTo(button);
//添加ok按钮事件
ok.hover(function () {
$(this).addClass("datebox-button-hover");
}, function () {
$(this).removeClass("datebox-button-hover");
}).click(function () {
_enter(jq);
});
}
datetimebox.spinner.timespinner({
showSeconds: options.showSeconds,
separator: options.timeSeparator
}).unbind(".datetimebox").bind("mousedown.datetimebox", function (e) {
e.stopPropagation();
});
_setValue(jq, options.value);
};
//获取当前年月日时分秒
function currentNewData(jq) {
var calendar = $(jq).datetimebox("calendar");
var spinner = $(jq).datetimebox("spinner");
var current = calendar.calendar("options").current;
return new Date(current.getFullYear(),
current.getMonth(),
current.getDate(),
spinner.timespinner("getHours"),
spinner.timespinner("getMinutes"),
spinner.timespinner("getSeconds"));
};
function _query(jq, q) {
_setValue(jq, q, true);
};
function _enter(jq) {
var options = $.data(jq, "datetimebox").options;
var data = currentNewData(jq);
_setValue(jq, options.formatter.call(jq, data));
$(jq).combo("hidePanel");
};
//赋值
function _setValue(jq, value, _15) {
var options = $.data(jq, "datetimebox").options;
$(jq).combo("setValue", value);
if (!_15) {
if (value) {
var value = options.parser.call(jq, value);
$(jq).combo("setValue", options.formatter.call(jq, value));
$(jq).combo("setText", options.formatter.call(jq, value));
} else {
$(jq).combo("setText", value);
}
}
var value = options.parser.call(jq, value);
$(jq).datetimebox("calendar").calendar("moveTo", value);
$(jq).datetimebox("spinner").timespinner("setValue", getdata(value));
function getdata(data) {
//获取小时
function gethour(hour) {
return (hour < 10 ? "0" : "") + hour;
};
var tt = [gethour(data.getHours()), gethour(data.getMinutes())];
if (options.showSeconds) {
tt.push(gethour(data.getSeconds()));
}
return tt.join($(jq).datetimebox("spinner").timespinner("options").separator);
};
};
//实例化
$.fn.datetimebox = function (target, parm) {
if (typeof target == "string") {
var method = $.fn.datetimebox.methods[target];
if (method) {
return method(this, parm);
} else {
return this.datebox(target, parm);
}
}
target = target || {};
return this.each(function () {
var datetimebox = $.data(this, "datetimebox");
if (datetimebox) {
$.extend(datetimebox.options, target);
} else {
$.data(this, "datetimebox", {
options: $.extend({},
$.fn.datetimebox.defaults,
$.fn.datetimebox.parseOptions(this),
target)
});
}
init(this);
});
};
//默认方法
$.fn.datetimebox.methods = {
//返回属性对象
options: function (jq) {
var options = $.data(jq[0], "datetimebox").options;
options.originalValue = jq.datebox("options").originalValue;
return options;
},
//返回时间微调器对象
spinner: function (jq) {
return $.data(jq[0], "datetimebox").spinner;
},
//赋值
setValue: function (jq, value) {
return jq.each(function () {
_setValue(this, value);
});
},
//重置
reset: function (jq) {
return jq.each(function () {
var options = $(this).datetimebox("options");
$(this).datetimebox("setValue", options.originalValue);
});
}
};
//解析器
$.fn.datetimebox.parseOptions = function (target) {
var spinner = $(target);
return $.extend({}, $.fn.datebox.parseOptions(target),
$.parser.parseOptions(target, ["timeSeparator", { showSeconds: "boolean" }]));
};
//日期时间输入框 默认属性和事件
$.fn.datetimebox.defaults = $.extend({}, $.fn.datebox.defaults, {
showSeconds: true,//定义是否显示秒钟信息
timeSeparator: ":",//定义在小时、分钟和秒之间的时间分割字符
//键盘事件
keyHandler: {
up: function () {
},
down: function () {
},
enter: function () {
_enter(this);
},
query: function (q) {
_query(this, q);
}
},
//格式化日期
formatter: function (data) {
var h = data.getHours();
var M = data.getMinutes();
var s = data.getSeconds();
function gethour(h) {
return (h < 10 ? "0" : "") + h;
};
var spinner = $(this).datetimebox("spinner").timespinner("options").separator;
var r = $.fn.datebox.defaults.formatter(data) + " " + gethour(h) + spinner + gethour(M);
if ($(this).datetimebox("options").showSeconds) {
r += spinner + gethour(s);
}
return r;
},
//解析器
parser: function (s) {
if ($.trim(s) == "") {
return new Date();
}
var dt = s.split(" ");
var d = $.fn.datebox.defaults.parser(dt[0]);
if (dt.length < 2) {
return d;
}
var spinner = $(this).datetimebox("spinner").timespinner("options").separator;
var tt = dt[1].split(spinner);
var hour = parseInt(tt[0], 10) || 0;
var minute = parseInt(tt[1], 10) || 0;
var second = parseInt(tt[2], 10) || 0;
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), hour, minute, second);
}
});
})(jQuery);

示例代码

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic DateTimeBox - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery-1.8.0.min.js"></script>
<script src="../../plugins2/jquery.parser.js"></script>
<script src="../../plugins2/jquery.validatebox.js"></script>
<script src="../../plugins2/jquery.panel.js"></script>
<script src="../../plugins2/jquery.combo.js"></script>
<script src="../../plugins2/jquery.calendar.js"></script>
<script src="../../plugins2/jquery.datebox.js"></script>
<script src="../../plugins2/jquery.validatebox.js"></script>
<script src="../../plugins2/jquery.spinner.js"></script>
<script src="../../plugins/jquery.timespinner.js"></script>
<script src="../../plugins2/jquery.datetimebox.js"></script>
</head>
<body>
<h2>Basic DateTimeBox</h2>
<div class="demo-info">
<div class="demo-tip icon-tip"></div>
<div>Click the calendar image on the right side.</div>
</div>
<div style="margin:10px 0;"></div>
<input class="easyui-datetimebox" required style="width:150px">
</body>
</html>

插件效果

easyui源码翻译1.32--DateTimeBox(日期时间输入框)的更多相关文章

  1. easyui源码翻译1.32+API翻译全篇导航 (提供下载源码)

    前言 EasyUI每个组件都会有 属性.方法.事件 属性 所有的属性都定义在jQuery.fn.{plugin}.defaults里面.例如,对话框属性定义在jQuery.fn.dialog.defa ...

  2. easyui源码翻译1.32--DateBox(日期输入框)

    前言 扩展自$.fn.combo.defaults.使用$.fn.datebox.defaults重写默认值对象.下载该插件翻译源码 日期输入框结合了一个可编辑的文本框控件和允许用户选择日期的下拉日历 ...

  3. 第二百一十九节,jQuery EasyUI,DateTimeBox(日期时间输入框)组件

    jQuery EasyUI,DateTimeBox(日期时间输入框)组件 学习要点: 1.加载方式 2.属性列表 3.方法列表 本节课重点了解 EasyUI 中 DateTimeBox(日期时间输入框 ...

  4. DateTimeBox( 日期时间输入框)

    本节课重点了解 EasyUI 中 DateTimeBox(日期时间输入框)组件的使用方法,这个组件依赖于 DateBox(日期输入框)组件和 TimeSpinner(时间微调)组件. 一. 加载方式/ ...

  5. easyui源码翻译1.32--datagrid(数据表格)

    前言 此前网上有easyui1.25的源码  应该算是比较老的版本  之后又经历了1.26 . 1.3. 1.31. 1.32 .1.33.1.34  1.33开始支持css3 算是又一个转折  但是 ...

  6. easyui源码翻译1.32--EasyLoader(简单加载)

    前言 扩展自$.fn.datebox.defaults,使用$.fn.datetimebox.defaults重写默认值对象.下载该插件翻译源码 源码 /** * jQuery EasyUI 1.3. ...

  7. easyui源码翻译1.32--Form(表单)

    前言 使用$.fn.form.defaults重写默认值对象下载该插件翻译源码 form提供了各种方法来操作执行表单字段,比如:ajax提交, load, clear等等.当提交表单的时候可以调用va ...

  8. easyui源码翻译1.32--Calendar(日历)

    前言 前几天加班比较忙 未能及时更新翻译的 今天多发布几篇..下载该插件翻译源码 日历控件显示一个月的日历,允许用户选择日期和移动到下一个或上一个月.默认情况下,一周的第一天是周日.它可以通过设置'f ...

  9. easyui源码翻译1.32--TimeSpinner(时间微调)

    前言 扩展自$.fn.spinner.defaults.使用$.fn.timespinner.defaults重写默认值对象.下载该插件翻译源码 时间微调组件的创建基于微调组件.它和数字微调类似,但是 ...

随机推荐

  1. Unity3D 之连按移动加速

    上代码: 效果是连续按W后,加速移动 为物体添加个拖拽效果,方便看运动轨迹. 将下面的脚本绑定到移动的物体上. 不过这里有一点很重要的需要去注意就是该方法不能放在 void FixedUpdate() ...

  2. 分析Redis架构设计

    http://blog.csdn.net/a600423444/article/details/8944601 一.前言 因为近期项目中开始使用Redis,为了更好的理解Redis并应用在适合的业务场 ...

  3. 关于H5中的Canvas API的探索

    Canvas API 是H5中比较炫酷的一部分内容.可以通过它动态的生成和展示图形.图表.图像以及动画.下面我将学习一下Canvas API. 最后有书籍和源码. 一.概述: 1.基本元素: 在网页上 ...

  4. Android入门开发之销毁activity

    使用: 销毁.关闭页面activity 如果打开下个页面的同时销毁了本页面,在下个页面无法返回本页面,每次打开APP应用就会先显示一张APP的介绍图.或者LOGO页面,延时几秒进入应用,进入后无法再返 ...

  5. let 与 expr Shell运算比较 let强强胜出

    Shell脚本中 整数运算一般通过 let 和 expr 这两个指令来实现,如对变量 s 加 1 可以写作:let "s = $s + 1" 或者 s=`expr $s + 1'两 ...

  6. Android--LowMemoryKiller知识点补充

    Android在内存管理上与linux有些小的区别.其中一个就是引入了Low memory killer . 1.引入原因: Android是一个多任务系统,也就是说可以同时运行多个程序,这个大家应该 ...

  7. HDU 3943 K-th Nya Number(数位DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3943 题目大意:求出区间 (P,Q] 中找到第K个满足条件的数,条件是该数包含X个4和Y个7 Samp ...

  8. 堆排序 C++

    1 堆排序拥有插入排序的优点 (是一种原地排序算法只需要存储常数个元素在输入数组以外 即省空间), 同时拥有合并排序算法的复杂度 nlgn,逼格有点高 2 堆数据结构 是一个数组对象,可以被视为一颗完 ...

  9. java nio使用方法(转)

    最近由于工作关系要做一些Java方面的开发,其中最重要的一块就是Java NIO(New I/O),尽管很早以前了解过一些,但并没有认真去看过它的实现原理,也没有机会在工作中使用,这次也好重新研究一下 ...

  10. 动态链接库找不到 : error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory

    问题: 运行gsl(GNU scientific Library)的函数库,用 gcc erf.c -I/usr/local/include -L/usr/local/lib64 -L/usr/loc ...