解决方案 »
- 问题求助
- jquery1.3.2 判断哪些复选框选中, 奇怪的问题。
- 一个非常奇特的问题~~~有点怪
- ******************************for in document.body 怎么打印出这么多(超乎想象的)???
- 如何把一串字符中的+号替换成2%b
- iframe 不能正常显示
- 下拉框与数据库的数据动态连接(菜鸟求救)
- <script language="javascript" src="../test.js"></script>的问题
- 老貼再問__有沒有javascript 的解決方法啊
- 二维数组的最大最小值求法
- iframe高度自适应问题,请教高手
- 请教一个 JS 为元素加“事件”的问题
{
this.WriteHead(yy, mm);
//设置当前年月的公共变量为传入值
this.L_TheYear = yy;
this.L_TheMonth = mm;
//当页面本身位于框架中时 IE会返回错误的parent
if (window.top.location.href != window.location.href) {
for (var i_f = 0; i_f < window.top.frames.length; i_f++) {
if (window.top.frames[i_f].location.href == window.location.href) { L_DateLayer_Parent = window.top.frames[i_f]; }
}
}
else {
L_DateLayer_Parent = window.parent;
}
for (var i = 0; i < 39; i++) { this.L_WDay[i] = "" }; //将显示框的内容全部清空
var day1 = 1, day2 = 1, firstday = new Date(yy, mm - 1, 1).getDay(); //某月第一天的星期几
for (i = 0; i < firstday; i++) this.L_WDay[i] = this.GetMonthCount(mm == 1 ? yy - 1 : yy, mm == 1 ? 12 : mm - 1) - firstday + i + 1 //上个月的最后几天
for (i = firstday; day1 < this.GetMonthCount(yy, mm) + 1; i++) { this.L_WDay[i] = day1; day1++; }
for (i = firstday + this.GetMonthCount(yy, mm); i < 39; i++) { this.L_WDay[i] = day2; day2++ }
for (i = 0; i < 39; i++) {
var da = this.GetDateLayer().document.getElementById("L_calendar-day_" + i + "");
var month, day;
if (this.L_WDay[i] != "") {
if (i < firstday) {
da.innerHTML = "<b style=\"color:gray\">" + this.L_WDay[i] + "</b>";
month = (mm == 1 ? 12 : mm - 1);
day = this.L_WDay[i];
}
else if (i >= firstday + this.GetMonthCount(yy, mm)) {
da.innerHTML = "<b style=\"color:gray\">" + this.L_WDay[i] + "</b>";
month = (mm == 1 ? 12 : mm + 1);
day = this.L_WDay[i];
}
else {
da.innerHTML = "<b style=\"color:#000\">" + this.L_WDay[i] + "</b>";
month = (mm == 1 ? 12 : mm);
day = this.L_WDay[i];
} //modify:120718 允许选择跨月日期
if (document.all) {
da.onclick = Function("L_DateLayer_Parent." + this.NewName + ".DayClick(" + month + "," + day + ")");
} else {
da.setAttribute("onclick", "parent." + this.NewName + ".DayClick(" + month + "," + day + ")");
} da.title = month + " 月" + day + " 日";
da.style.background = (yy == new Date().getFullYear() && month == new Date().getMonth() + 1 && day == new Date().getDate()) ? "#FFD700" : "#e0e0e0";
if (this.InputDate != null) {
if (yy == this.InputDate.getFullYear() && month == this.InputDate.getMonth() + 1 && day == this.InputDate.getDate()) {
da.style.background = "#0650D2";
}
}
}
}
},
SelectYearInnerHTML: function (strYear) //年份的下拉框
{
var prevY = 60, nextY = 5; //modify:120718
if (strYear.match(/\D/) != null) { alert("年份输入参数不是数字!"); return; }
var m = (strYear) ? strYear : new Date().getFullYear();
if (m < 1000 || m > 9999) { alert("年份值不在 1000 到 9999 之间!"); return; }
var n = m - prevY;
if (n < 1000) n = 1000;
if (n + nextY > 9999) n = 9999 - nextY;
var s = "<select name=\"L_SelectYear\" id=\"L_SelectYear\" style='font-size: 12px' "
s += "onblur='document.getElementById(\"SelectYearLayer\").style.display=\"none\"' "
s += "onchange='document.getElementById(\"SelectYearLayer\").style.display=\"none\";"
s += "parent." + this.NewName + ".L_TheYear = this.value; parent." + this.NewName + ".SetDay(parent." + this.NewName + ".L_TheYear,parent." + this.NewName + ".L_TheMonth)'>\r\n";
var selectInnerHTML = s;
for (var i = n; i < n + prevY + nextY; i++) //modify:120718
{
if (i == m)
{ selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n"; }
else { selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n"; }
}
selectInnerHTML += "</select>";
var DateLayer = this.GetDateLayer();
DateLayer.document.getElementById("SelectYearLayer").style.display = "";
DateLayer.document.getElementById("SelectYearLayer").innerHTML = selectInnerHTML;
DateLayer.document.getElementById("L_SelectYear").focus();
},
SelectMonthInnerHTML: function (strMonth) //月份的下拉框
{
if (strMonth.match(/\D/) != null) { alert("月份输入参数不是数字!"); return; }
var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
var s = "<select name=\"L_SelectYear\" id=\"L_SelectMonth\" style='font-size: 12px' "
s += "onblur='document.getElementById(\"SelectMonthLayer\").style.display=\"none\"' "
s += "onchange='document.getElementById(\"SelectMonthLayer\").style.display=\"none\";"
s += "parent." + this.NewName + ".L_TheMonth = this.value; parent." + this.NewName + ".SetDay(parent." + this.NewName + ".L_TheYear,parent." + this.NewName + ".L_TheMonth)'>\r\n";
var selectInnerHTML = s;
for (var i = 1; i < 13; i++) {
if (i == m)
{ selectInnerHTML += "<option value='" + i + "' selected>" + i + "月" + "</option>\r\n"; }
else { selectInnerHTML += "<option value='" + i + "'>" + i + "月" + "</option>\r\n"; }
}
selectInnerHTML += "</select>";
var DateLayer = this.GetDateLayer();
DateLayer.document.getElementById("SelectMonthLayer").style.display = "";
DateLayer.document.getElementById("SelectMonthLayer").innerHTML = selectInnerHTML;
DateLayer.document.getElementById("L_SelectMonth").focus();
},
DayClick: function (mm, dd) //点击显示框选取日期,主输入函数*************
{
var yy = this.L_TheYear;
//判断月份,并进行对应的处理
if (mm < 1) { yy--; mm = 12 + mm; }
else if (mm > 12) { yy++; mm = mm - 12; }
if (mm < 10) { mm = "0" + mm; }
if (this.ClickObject) {
if (!dd) { return; }
if (dd < 10) { dd = "0" + dd; }
this.InputObject.value = yy + "-" + mm + "-" + dd; //注:在这里你可以输出改成你想要的格式
if (this.OutMode == 'y-m') this.InputObject.value = yy + "-" + mm; //modify:120718
this.CloseLayer();
}
else { this.CloseLayer(); alert("您所要输出的控件对象并不存在!"); }
},
SetDate: function () {
if (arguments.length < 1) { alert("对不起!传入参数太少!"); return; }
else if (arguments.length > 2) { alert("对不起!传入参数太多!"); return; }
this.InputObject = (arguments.length == 1) ? arguments[0] : arguments[1];
this.ClickObject = arguments[0];
var reg = /^(\d+)-(\d{1,2})-(\d{1,2})$/;
var r = this.InputObject.value.match(reg);
if (r != null) {
r[2] = r[2] - 1;
var d = new Date(r[1], r[2], r[3]);
if (d.getFullYear() == r[1] && d.getMonth() == r[2] && d.getDate() == r[3]) {
this.InputDate = d; //保存外部传入的日期
}
else this.InputDate = "";
this.L_TheYear = r[1];
this.L_TheMonth = r[2] + 1;
}
else {
this.L_TheYear = new Date().getFullYear();
this.L_TheMonth = new Date().getMonth() + 1
}
this.CreateHTML();
var top = this.GetY();
var left = this.GetX();
var DateLayer = document.getElementById("L_DateLayer");
DateLayer.style.top = top + this.ClickObject.clientHeight + 5 + "px";
DateLayer.style.left = left + "px";
DateLayer.style.display = "block";
if (document.all) {
this.GetDateLayer().document.getElementById("L_calendar").style.width = "160px";
this.GetDateLayer().document.getElementById("L_calendar").style.height = "180px"
}
else {
this.GetDateLayer().document.getElementById("L_calendar").style.width = "154px";
this.GetDateLayer().document.getElementById("L_calendar").style.height = "180px"
DateLayer.style.width = "158px";
DateLayer.style.height = "250px";
}
//alert(DateLayer.style.display)
this.SetDay(this.L_TheYear, this.L_TheMonth);
}, CloseLayer: function () {
try {
var DateLayer = document.getElementById("L_DateLayer");
if ((DateLayer.style.display == "" || DateLayer.style.display == "block") && arguments[0] != this.ClickObject && arguments[0] != this.InputObject) {
DateLayer.style.display = "none";
}
}
catch (e) { }
}
}document.writeln('<iframe id="L_DateLayer" name="L_DateLayer" frameborder="0" style="position:absolute;width:160px; height:200px;z-index:9998;display:none;"></iframe>');
var L_DateLayer_Parent = null;
var gRiLi = new L_calendar();
gRiLi.NewName = "gRiLi";document.onclick = function (e) {
e = window.event || e;
var srcElement = e.srcElement || e.target;
gRiLi.CloseLayer(srcElement);
}
function imgCalendar(theID, pStyle) {
var s = "";
s += "<img onclick='gRiLi.SetDate(this,document.getElementById(\"" + theID + "\"))' alt='选择日期' style='CURSOR:hand;vertical-align:middle;margin-bottom:3px;' src='../images/button/selTime.gif'>";
document.write(s);
}function popCalendar(pThis, pStyle) {
if (typeof (pStyle) != 'undefined') gRiLi.OutMode = pStyle;
gRiLi.SetDate(pThis);
}
else {
da.innerHTML = "<b style=\"color:#000\">" + this.L_WDay[i] + "</b>";
//month = (mm == 1 ? 12 : mm);
month =mm;
day = this.L_WDay[i];
}month = (mm == 1 ? 12 : mm); 改成 month =mm;
这里是设定当前月份的日期,不需要特别处理