求,js时间控件,不要带日期的,该怎么处理

作者&投稿:衷柯 (若有异议请与网页底部的电邮联系)
js 或 jquery时间控件,不要日期~

建议:

如果只要时,分,秒,根本不需要什么控件。直接写三个下拉菜单选择就OK。

网上找的控件都是带日期的,难点就是日期处理上面。

所以不要日期的控件,因为太容易办到,反而没现成提供。自己写罢,美工美化下就OK。

只是后台传值的处理上要麻烦点,要经过几个手工格式转换

js日期控件 限制选择日期(只能选择指定日期)
日期空间 貌似都有限制的功能

已写成控件, 显示格式 由外部传参调用 如SelectDate(this,hh:mm)
由于上传字数限制,代码不完整。可加好友,私信,免费提供,无偿共享代码。
/// FileName:calendar.js
var cal;
var isFocus = false; //是否为焦点
var pickMode = {
"second": 1,
"minute": 2,
"hour": 3,
"day": 4,
"month": 5,
"year": 6
};
var topY = 0, leftX = 0; //自定义定位偏移量
//选择日期,通过 ID 来选日期
function SelectDateById(id, strFormat, minYear, maxYear, x, y) {
var obj = document.getElementById(id);
if (obj == null) { return false; }
obj.focus();
if (obj.onclick != null) { obj.onclick(); }
else if (obj.click != null) { obj.click(); }
else { SelectDate(obj, strFormat, x, y) }
}
/**//**//**//**//**//**//**//**
* 返回日期
* @param d the delimiter
* @param p the pattern of your date
根据用户指定的 style 来确定;
*/
String.prototype.toDate = function(style) {
var y = this.substring(style.indexOf('y'), style.lastIndexOf('y') + 1); //年
var M = this.substring(style.indexOf('M'), style.lastIndexOf('M') + 1); //月
var d = this.substring(style.indexOf('d'), style.lastIndexOf('d') + 1); //日
var h = this.substring(style.indexOf('h'), style.lastIndexOf('h') + 1); //时
var m = this.substring(style.indexOf('m'), style.lastIndexOf('m') + 1); //分
var s = this.substring(style.indexOf('s'), style.lastIndexOf('s') + 1); //秒
if (s == null || s == "" || isNaN(s)) { s = new Date().getSeconds(); }
if (m == null || m == "" || isNaN(m)) { m = new Date().getMinutes(); }
if (h == null || h == "" || isNaN(h)) { h = new Date().getHours(); }
if (d == null || d == "" || isNaN(d)) { d = new Date().getDate(); }
if (M == null || M == "" || isNaN(M)) { M = new Date().getMonth() + 1; }
if (y == null || y == "" || isNaN(y)) { y = new Date().getFullYear(); }
var dt;
eval("dt = new Date('" + y + "', '" + (M - 1) + "','" + d + "','" + h + "','" + m + "','" + s + "')");
return dt;
}

//显示日历
Calendar.prototype.show = function(dateObj, strFormat, minYear, maxYear, popControl) {
if (dateObj == null) {
throw new Error("arguments[0] is necessary")
}
this.dateControl = dateObj;
var now = new Date();
var str = dateObj.value;
var strtodate = strToDate(str, strFormat, minYear, maxYear); //格式检查
this.date = (dateObj.value.length > 0 && strtodate == true) ?
new Date(dateObj.value.toDate(this.dateFormatStyle)) :
now.format(this.dateFormatStyle).toDate(this.dateFormatStyle); //不为空、且格式验证通过,根据日期框实际日期初使化

// this.date = (dateObj.value.length > 0 && strtodate == false) ? //不为空、且格式验证不通过,根据当前日期初使化
// new Date(now.toLocaleString().toDate(this.dateFormatStyle)) :
// now.format(this.dateFormatStyle).toDate(this.dateFormatStyle);
if (this.panel.innerHTML == "" || cal.dateFormatStyleOld != cal.dateFormatStyle)//2008-01-29 把构造表格放在此处,2009-03-03 若请示的样式改变,则重新初始化
{
this.draw();
this.bindYear();
this.bindMonth();
this.bindHour();
this.bindMinute();
this.bindSecond();
}
this.year = this.date.getFullYear();
this.month = this.date.getMonth();
this.day = this.date.getDate();
this.hour = this.date.getHours();
this.minute = this.date.getMinutes();
this.second = this.date.getSeconds();
this.changeSelect();
this.bindData();
this.container.style.display = ""; //必须先显示 calendarPanel,不然获取高度是0

// if (popControl == null) {
// popControl = dateObj;
// }
// var xy = this.getAbsPoint(popControl); //20170608注释。 在从表会出位置有偏移的问题,改面下面的方式直接取
//getBoundingClientRect()最先是IE的私有属性,现在已经是一个W3C标准。所以不用当心浏览器兼容问题,
//除了safari,firefox2.0外所有浏览器都支持getBoundingClientRect
var ro = dateObj.getBoundingClientRect();
var Top = ro.top;
var Bottom = ro.bottom;
var Height = ro.height || Bottom - Top;
var X = dateObj.getBoundingClientRect().left + document.documentElement.scrollLeft;
var Y = dateObj.getBoundingClientRect().top + document.documentElement.scrollTop;
var vcalendarHeight = $('#calendarPanel').height();
var vBottom = $(window).height() - Bottom;
if (vBottom >= vcalendarHeight) {
this.panel.style.top = (Y + topY + Height) + "px";
}
else {
this.panel.style.top = (Y + topY - vcalendarHeight - 3) + "px"; //加偏移量3才不会档住text文本框
}
this.panel.style.left = (X + leftX) + "px"; // leftX topY 自定义偏移量
this.panel.style.display = "";
//把 visibility 变为 display,并添加失去焦点的事件 //this.setDisplayStyle("select", "hidden");
//this.panel.style.visibility = "visible";
//this.container.style.visibility = "visible";
if (!this.dateControl.isTransEvent) {
this.dateControl.isTransEvent = true;
/* 已写在返回值的时候 ReturnDate 函数中,去除验证事件的函数
this.dateControl.changeEvent = this.dateControl.onchange;//将 onchange 转成其它函数,以免触发验证事件
this.dateControl.onchange = function()
{if(typeof(this.changeEvent) =='function'){this.changeEvent();}}*/
if (this.dateControl.onblur != null) {
this.dateControl.blurEvent = this.dateControl.onblur;
} //2007-09-14 保存主文本框的 onblur ,使其原本的事件不被覆盖
this.dateControl.onblur = function() {
calendar.onblur();
if (typeof (this.blurEvent) == 'function') {
this.blurEvent();
}
}
}
this.container.onmouseover = function() { isFocus = true; }
this.container.onmouseout = function() { isFocus = false; }
}

//格式检查
function strToDate(str, A1SizeDateFormat, by, ey) {
var date = new Date();
if (A1SizeDateFormat == "hh:mm") {
var timeTemp = str.split(":");
var strhours = timeTemp[0];
var strminutes = timeTemp[1];
var seperator1 = ":";
if (strhours == undefined) {
strhours = date.gethours();
}
if (strhours == 24) {
strhours = "00";
}
if (strminutes == undefined || strminutes == "") {
strminutes = date.getMinutes();
}
var newtime = new Date(date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate() + ' ' + strhours + ':' + strminutes);
if (newtime.getHours() == strhours && newtime.getMinutes() == strminutes) {
return true;
}
else {
return false;
}
}
else {
by = date.getFullYear() - Number(by) | 0;
ey = date.getFullYear() + Number(ey) | 0;
var arrTemp = str.split("-");
var stryear = arrTemp[0];
var strmonth = arrTemp[1];
var strdate = arrTemp[2];
var seperator2 = "-";
if (stryear < by || stryear > ey || stryear == undefined) {
return false;
}
if (strmonth == undefined || strmonth == "") {
strmonth = date.getMonth() + 1;
}
if (strmonth >= 1 && strmonth <= 9 && strmonth.toString().length == 1) {
strmonth = "0" + strmonth;
}
if (strdate == undefined || strdate == "") {
strdate = date.getDate();
}
if (strdate >= 0 && strdate <= 9 && strdate.toString().length == 1) {
strdate = "0" + strdate;
}
var newdate = new Date(stryear + '/' + strmonth + '/' + strdate);
if (newdate.getYear() == stryear && newdate.getMonth() + 1 == strmonth && newdate.getDate() == strdate) {
if (A1SizeDateFormat == "yyyy-MM") {
return true;
}
else if (A1SizeDateFormat == "yyyy-MM-dd") {
return true;
}
}
}
}

//隐藏日历
Calendar.prototype.hide = function() {
//this.setDisplayStyle("select", "visible");
//this.panel.style.visibility = "hidden";
//this.container.style.visibility = "hidden";
this.panel.style.display = "none";
this.container.style.display = "none";
isFocus = false;
}
//焦点转移时隐藏日历
Calendar.prototype.onblur = function() {
if (!isFocus) { this.hide(); }
}
//确保日历容器节点在 body 最后,否则 FireFox 中不能出现在最上方
function InitContainerPanel() //初始化容器
{
var str = '<div id="calendarPanel" style="position: absolute;display: none;z-index:9999; background-color: #FFFFFF;border: 1px solid #CCCCCC;width:175px;font-size:12px;"></div>';
// if (document.all) {
// str += '<iframe style="position:absolute;z-index:2000;width:expression(this.previousSibling.offsetWidth);';
// str += 'height:expression(this.previousSibling.offsetHeight);';
// str += 'left:expression(this.previousSibling.offsetLeft);top:expression(this.previousSibling.offsetTop);';
// str += 'display:expression(this.previousSibling.style.display);" scrolling="no" frameborder="no"></iframe>';
// }//20170608注释。在IE8非兼容模式下,会多出一个html内嵌iframe,导致遮挡其它内容
var div = document.createElement("div");
div.innerHTML = str;
// var para = document.createElement(str)
// div.appendChild(para);
div.id = "ContainerPanel";
div.style.display = "none";
document.body.appendChild(div);
} //调用calendar.show(dateControl, popControl);

<span id= "liveclock " style "=width: 109px; height: 15px "> </span>

<SCRIPT language=javascript>
<!--
function www_mdrcw_com()
{
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
if(minutes <=9)
minutes= "0 "+minutes
if(seconds <=9)
seconds= "0 "+seconds
myclock= " "+hours+ ": "+minutes+ ": "+seconds+ " </font> "
if(document.layers){document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}else if(document.all)
liveclock.innerHTML=myclock
setTimeout( "www_mdrcw_com() ",1000)
}
www_mdrcw_com();
//-->
</SCRIPT>


什么是js控件
就是一些用Javascript写好的功能,可能是有界面的,也可能是没有界面的。比较常见的比如一些网页上有日期选择的效果,一般都是用所谓的javascript控件实现的。

为什么我运行这个js日期控件总是报缺少对象
服务器ID与客户端ID不一致造成此问题。 由于服务器端控件在生成html时,id会发生变化,所以在js直接取服务器端控件id时会找不到对象。 解决方法: 1.运行网页文件,查看源文件,将相应的html生成的控件id替换现有js内的控件Id

日历控件
我想要个直接能在页面上显示的日历控件,(不刷新页面的),有谁能帮一下忙谢谢... 我想要个直接能在...建一个JS文件,比如名字为jsDate.js将以下代码COPY进去<!--document.write("")

给小莹莹的bootstrap时间控件js
首先,我们将这款日期控件下载下来。百度bootstrap日期控件即可。将下载好的日期控件的css、js引入自己的文件中。在这里需要引入的文件有:bootstrap.min.css(含有bootstrap 所有css)bootstrap-datetimepicker.min.css(重要,这就是日期控件所需的样式表)jquery-1.8.3.min.js(其他版本的jquery也可以...

页面上写了一个js日期控件,可是选了日期之后日期值无法传递到后台,求...
你把dealTime的value打印出来看看,还有你dealTime没有名字,后台获取是根据名字来的,你给标签一个名字再试。祝你成功

...的日期变成灰色并且不能选,我用的是My97DatePicker JS时间控件...
2、先把代码写上,最重要的是input控件的使用。将type类型设为“date”,就是日历类型了。3、点击选框就会弹出日历框。4、也有时间选框类型,type设置为“time”。5、不同可以改变不同类型。以下是其余的常用type归类,日期时间控件 type = "datetime-local"。

我在网上找了个JS日历控件,里面有一段代码不知道是什么意思。请高手指...
回答:给窗体添加文档加载完成事件,接着就是用你下载的日期控件定义的类来初始化3个对象,具体的初始化参数自己看看那控件的说明文档吧

JS的日历控件的日期格式,输出已经改成YYYY\/MM\/DD了,但是传入的时候不能...
传入时用标准的,YYYY-MM-DD,如果用\/分隔符,需要符合美式或英式写法:最后一项是年。MM\/DD\/YYYY, 或DD\/MM\/YYYY YYYY\/MM\/DD, 常规来说,没这种写法。如果是年月日,通常采用"-"做分隔符。

js日期控件 限制选择日期(只能选择指定日期
日期空间 貌似都有限制的功能

...日期和时间,具体到年月日、小时、分钟的时间控件 麻烦发到我邮箱2447...
js 的datepicker插件,发给你了,给我分

宁晋县18498738536: 求一款只显示小时分钟的JS时间控件 -
焦房托马: 这个很简单 html:<span id='span_datetime'></span> //这个span就是你要在页面中显示时间的位置,id不动 js://以下js推荐放页面脚部 <script type="text/javascript"> window.onload = function () { var datetime = document.getElementById('span_...

宁晋县18498738536: extjs 如何禁用日期时间控件 -
焦房托马: 1、extjs日期控件禁用:设置editable:false这个属性即可. editable:是否可编辑,默认为true .2、Extjs日期控件禁止用户输入(设置readOnly为true):JScript 代码 :{xtype:"datefield",format:"Y-m-d",value:"1986-12-25",readOnly:true...

宁晋县18498738536: 求计算时间的js控件的代码?
焦房托马: 给你个我之前做的例子吧 <script> function CalDays() { var ERR_MSG = "输入的时间格式不正确"; var inp = start.getElementsByTagName("input");//获取起始年月日 var inp2 = end.getElementsByTagName("input");//获取结束年月日 ...

宁晋县18498738536: 求最简单的Javascript显示时间代码! -
焦房托马: <script language="JavaScript"> <!--function Time(){if (!document.layers&&!document.all)returnvar Timer=new Date()var hours=Timer.getHours()var minutes=Timer.getMinutes()var seconds=Timer.getSeconds()var noon="AM"if (...

宁晋县18498738536: 求计算时间的js控件的代码? -
焦房托马: 给你个我之前做的例子吧 请假起始日期: 年月日请假结束日期: 年月日 记得采纳啊

宁晋县18498738536: 在jsp中插入时间控件 -
焦房托马: 用WdatePicker 控件就可以 1.导入js文件 <script language="javascript" type="text/javascript" src="../js/datepicker/WdatePicker.js"> </script>2.在文本框中使用即可 <input type="text" id="temp" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})"/>

宁晋县18498738536: 求个简单的JavaScript时间输出 -
焦房托马: <script type="text/javascript">function getCurDate() {var d = new Date(); var week; switch (d.getDay()){ case 1: week="星期一"; break; case 2: week="星期二"; break; case 3: week="星期三"; break; case 4: week="星期四"; break...

宁晋县18498738536: JavaScript 日期选择控件,不要年,只要月和日,注意,屏蔽掉年至,只要月和日 -
焦房托马: 可以使用mobiscroll插件,这个插件的显示内容是可以进行自定义配置的

宁晋县18498738536: JS时间戳转换为正常时间时怎么只保留日期不要时间 -
焦房托马: //第一种<br>function getLocalTime(nS) { <br> return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '); <br>} <br>alert(getLocalTime(1293072805));<br>//结果是2010年12月23日 10:53//第二种 <br>function getLocalTime(nS) { <...

宁晋县18498738536: 如何用javascript做时间控件 -
焦房托马: 入到你的页面中 js/Calendar.js 这是控件的路径 这是我的,你看看.Calendar.js 这个东西应该可以找的到吧,onclick="SelectDate(this)" 这是调用

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网