1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
(function() { 'use strict'; var timeTemplateEle = $('<div style="display: inline; position: fixed; z-index:10000; right: 10px; top: 10px;"><input type="number" id="time-ipt" /> <span id="time-result"></span></div>'); var dateTemplateEle = $('<div style=" display: inline; position: fixed; z-index: 10000; right: 10px; top: 10px;"><input type="date" id="date-ipt" /> <span id="date-result"></span></div>'); var bodyEle = $("body"); var timeResultEle = $("#time-result", timeTemplateEle); var timeIptEle = $("#time-ipt", timeTemplateEle); var cssStyle = { "font-size": "12px", "padding": " 5px", "color": "#555", "vertial-align": "middle", "border": "1px solid #ccc", "border-radius": "3px", }; timeIptEle.css(cssStyle);
var dateResultEle = $("#date-result", dateTemplateEle); var dateIptEle = $("#date-ipt", dateTemplateEle); dateIptEle.css(cssStyle); var keyCounter = new Map();
bodyEle.on("keyup", "#time-ipt", function (evt) { var timeIptEle = $(this); if (evt.keyCode == 13) { var value = timeIptEle.val(); if ($.trim(value) === "") { alert(" Please Input Value ! "); } else { var dateObj = new Date(value * 1000); timeResultEle.html(dateObj.getFullYear() + '/' + (dateObj.getMonth() + 1) + '/' + dateObj.getDate() + ' ' + dateObj.getHours() + ':' + dateObj.getMinutes() + ':' + dateObj.getSeconds()); } } else if (evt.keyCode == 27) { timeTemplateEle.remove(); } });
bodyEle.on("keyup", "#date-ipt", function (evt) { var dateIptEle = $(this); if (evt.keyCode == 13) { var value = dateIptEle.val(); if ($.trim(value) === "") { alert(" Please Input Date ! "); } else { var dateObj = new Date(value); dateResultEle.html(dateObj.getTime()); return; } } else if (evt.keyCode == 27) { dateTemplateEle.remove(); } });
bodyEle.on("keyup", function (evt) { var keyCode = evt.keyCode, keyFlag = 'key-' + keyCode, keyCount = keyCounter.get(keyFlag) || 0;
if (keyCode == 84) { keyCounter.set(keyFlag, ++keyCount); if (keyCount == 3) { bodyEle.prepend(timeTemplateEle); timeIptEle.focus(); keyCounter.clear(); } } else if (keyCode == 68) { keyCounter.set(keyFlag, ++keyCount); if (keyCount === 3) { bodyEle.prepend(dateTemplateEle); dateIptEle.focus(); keyCounter.clear(); } } else { keyCounter.clear(); } }); })();
|