jquery版本:jquery-1.4.4.js
我的页面:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<script type="text/javascript">
<!--
/**
 * BoxunDate
 * @param   beginYear           1990
 * @param   endYear             2010
 * @param   language            0(zh_cn)|1(en_us)|2(en_en)|3(zh_tw)
 * @param   patternDelimiter    "-"
 * @param   date2StringPattern  "yyyy-MM-dd"
 * @param   string2DatePattern  "ymd"
 * @version 1.0 build 2006-04-01
 * @version 1.1 build 2006-12-17
 * @author  KimSoft (jinqinghua [at] gmail.com)
 * NOTE!    you can use it free, but keep the copyright please
 * IMPORTANT:you must include this script file inner html body elment 
 */
function BoxunDate(beginYear, endYear, language, patternDelimiter, date2StringPattern, string2DatePattern) {
this.language  = language  || 0;
this.dateControl = null;
this.panel  = this.getElementById("__calendarPanel");
this.iframe = window.frames["__calendarIframe"];
this.form   = null; this.colors = {"bg_over":"#EFEFEF","bg_out":"#FFCC00","bg_select":"#FF0000"}
};
BoxunDate.language = {
"clear"  : ["\u6e05\u7a7a", "Clear", "Clear", "\u6e05\u7a7a"],
"close"  : ["\u5173\u95ed", "Close", "Close", "\u95dc\u9589"]
};
BoxunDate.prototype.draw = function() {
boxunDate = this;
var _cs = [];
_cs[_cs.length] = '<form id="__calendarForm" name="__calendarForm" method="post">';
_cs[_cs.length] = '<table id="__calendarTable" width="100%" border="0" cellpadding="3" cellspacing="1" align="center">';
for(var i = 0; i < 6; i++){
_cs[_cs.length] = '<tr align="center">';
for(var j = 0; j < 7; j++) {
switch (j) {
case 0: _cs[_cs.length] = '<td class="sun" tag="0">&nbsp;<\/td>'; break;
case 6: _cs[_cs.length] = '<td class="sat" tag="0">&nbsp;<\/td>'; break;
default:_cs[_cs.length] = '<td class="normal" tag="0">&nbsp;<\/td>'; break;
}
}
_cs[_cs.length] = '<\/tr>';
}
_cs[_cs.length] = ' <tr>';
_cs[_cs.length] = '  <th colspan="2"><input type="button" class="b" name="clearButton" id="clearButton" \/><\/th>';
_cs[_cs.length] = '  <th colspan="3"><input type="text" align="middle" style="vertical-align:middle" size="5" value="00:00" \/><\/th>';
_cs[_cs.length] = '  <th colspan="2"><input type="button" class="b" name="closeButton" id="closeButton" \/><\/th>';
_cs[_cs.length] = ' <\/tr>';
_cs[_cs.length] = '<\/table>';
_cs[_cs.length] = '<\/form>';

this.iframe.document.body.innerHTML = _cs.join("");
this.form = this.iframe.document.forms["__calendarForm"]; this.form.clearButton.value = BoxunDate.language["clear"][this.language];
this.form.closeButton.value = BoxunDate.language["close"][this.language];

this.form.clearButton.onclick = function () {boxunDate.dateControl.value = "";boxunDate.hide();}
this.form.closeButton.onclick = function () {boxunDate.hide();}
};  
BoxunDate.prototype.bindData = function () {
var boxunDate = this; 
var dateArray = this.getMonthViewDateArray();
var tds = this.getElementsByTagName("td", this.getElementById("__calendarTable", this.iframe.document));
for(var i = 0; i < tds.length; i++) {
   tds[i].style.backgroundColor = boxunDate.colors["bg_over"];
tds[i].onclick = null;
tds[i].onmouseover = null;
tds[i].onmouseout = null;
tds[i].innerHTML = dateArray[i] || "&nbsp;";
if (i > dateArray.length - 1) continue;
if (dateArray[i]){
tds[i].onclick = function () {
if (boxunDate.dateControl){
this.style.backgroundColor = boxunDate.colors["bg_select"]; 
this.setAttribute("tag","1");
if(boxunDate.dateControl.value==null||boxunDate.dateControl.value==''||boxunDate.dateControl.value.length==0){
boxunDate.dateControl.value = this.innerHTML;
}else{
var currdate = this.innerHTML;
var currArr = boxunDate.dateControl.value.split(",");
var count = 0;
var index = 0;
if (currArr.length > 0){
for (var i = 0; i< currArr.length; i++){
 if (currArr[i] == currdate){
count = 1;
index = i;
break;
 }
}
if (count == 1){
this.setAttribute("tag","0");
this.style.backgroundColor = boxunDate.colors["bg_out"]; 
if(index == 0){
if(currArr.length != 1){
currdate = currdate + ",";
}
}else{
currdate = "," + currdate;
}
boxunDate.dateControl.value = boxunDate.dateControl.value.replace(currdate,""); 
}else{
boxunDate.dateControl.value = boxunDate.dateControl.value +","+ currdate;
}  
}
}
}
//boxunDate.hide();
}
tds[i].onmouseover = function () {
this.style.backgroundColor = boxunDate.colors["bg_out"];
if(this.getAttribute("tag")==0){
this.style.backgroundColor = boxunDate.colors["bg_out"]; 

}
tds[i].onmouseout  = function () {this.style.backgroundColor = boxunDate.colors["bg_over"];
if(this.getAttribute("tag")==1){
this.style.backgroundColor = boxunDate.colors["bg_select"];


}   
if (boxunDate.dateControl.value.length > 0){
var valueArrays = boxunDate.dateControl.value.split(",");
for(var s in valueArrays){
if(valueArrays[s] == tds[i].innerHTML){
tds[i].setAttribute("tag","1");
tds[i].style.backgroundColor = boxunDate.colors["bg_select"]; 
}   
}        
}  
}//end if
}//end for
};BoxunDate.prototype.getMonthViewDateArray = function (y, m) {
//alert(y+'==='+m+'==='+new Date(y, m, 1).getDay()+'=='+new Date(y, m + 1, 0).getDate());
var dateArray = new Array(42);
for (var i = 0; i < 30; i++) {
dateArray[i + 1] = i + 1;

return dateArray;
};BoxunDate.prototype.show = function (dateControl, popuControl) {
if (this.panel.style.visibility == "visible") {
this.panel.style.visibility = "hidden";
}
if (!dateControl){
throw new Error("arguments[0] is necessary!")
}
this.dateControl = dateControl;
popuControl = popuControl || dateControl; this.draw();
this.bindData(); var xy = this.getAbsPoint(popuControl);
this.panel.style.left = xy.x + "px";
this.panel.style.top = (xy.y + dateControl.offsetHeight) + "px";
this.panel.style.visibility = "visible";
};BoxunDate.prototype.hide = function() {
this.panel.style.visibility = "hidden";
};/*
 * 获得单击该元素对象
 */
BoxunDate.prototype.getElementById = function(id, object){
object = object || document;     
return document.getElementById ? object.getElementById(id) : document.all(id);
};BoxunDate.prototype.getElementsByTagName = function(tagName, object){
object = object || document;
return document.getElementsByTagName ? object.getElementsByTagName(tagName) : document.all.tags(tagName);
};BoxunDate.prototype.getAbsPoint = function (e){
var x = e.offsetLeft;
var y = e.offsetTop;
while(e = e.offsetParent){
x += e.offsetLeft;
y += e.offsetTop;
}
return {"x": x, "y": y};
};
document.writeln('<div id="__calendarPanel" style="position:absolute;visibility:hidden;z-index:9999;background-color:#FFFFFF;border:1px solid #666666;width:200px;height:170px;">');
document.writeln('<iframe name="__calendarIframe" id="__calendarIframe" width="100%" height="100%" scrolling="no" frameborder="0" style="margin:0px;"><\/iframe>');
var __ci = window.frames['__calendarIframe'];
__ci.document.writeln('<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd">');
__ci.document.writeln('<html xmlns="http:\/\/www.w3.org\/1999\/xhtml">');
__ci.document.writeln('<head>');
__ci.document.writeln('<meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/>');
__ci.document.writeln('<title>Web BoxunDate(UTF-8) Written By KimSoft<\/title>');
__ci.document.writeln('<style type="text\/css">');
__ci.document.writeln('<!--');
__ci.document.writeln('body {font-size:12px;margin:0px;text-align:center;}');
__ci.document.writeln('form {margin:0px;}');
__ci.document.writeln('select {font-size:12px;background-color:#EFEFEF;}');
__ci.document.writeln('table {border:0px solid #CCCCCC;background-color:#FFFFFF}');
__ci.document.writeln('th {font-size:12px;font-weight:normal;background-color:#FFFFFF;}');
__ci.document.writeln('th.theader {font-weight:normal;background-color:#666666;color:#FFFFFF;width:24px;}');
__ci.document.writeln('select.year {width:64px;}');
__ci.document.writeln('select.month {width:60px;}');
__ci.document.writeln('td {font-size:12px;text-align:center;}');
__ci.document.writeln('td.sat {color:#0000FF;background-color:#EFEFEF;}');
__ci.document.writeln('td.sun {color:#FF0000;background-color:#EFEFEF;}');
__ci.document.writeln('td.normal {background-color:#EFEFEF;}');
__ci.document.writeln('input.l {border: 1px solid #CCCCCC;background-color:#EFEFEF;width:20px;height:20px;}');
__ci.document.writeln('input.r {border: 1px solid #CCCCCC;background-color:#EFEFEF;width:20px;height:20px;}');
__ci.document.writeln('input.b {border: 1px solid #CCCCCC;background-color:#EFEFEF;width:100%;height:20px;}');
__ci.document.writeln('-->');
__ci.document.writeln('<\/style>');
__ci.document.writeln('<\/head>');
__ci.document.writeln('<body>');  
__ci.document.writeln('<\/body>');
__ci.document.writeln('<\/html>');
__ci.document.close();
document.writeln('<\/div>');
var boxunDate = new BoxunDate();
//-->
</script>
       <div>
              <span>交易查询:</span> 
  <span>
                    <input name="control_date" type="text" id="control_date" size="100" value="5,12,19,26"
                        maxlength="10" onclick="new BoxunDate().show(this);" readonly="readonly" />
  </span>
       </div> 
上面这段JS直接使用是没有问题的,但是加入我的项目跟jquery有了冲突。
错误信息:
SCRIPT5007: 无法获取属性“document”的值: 对象为 null 或未定义 
jquery-1.4.4.js, 行608 字符4
完全不知道怎么弄了,求帮助,为啥子单独运行OK,加上jquery就出了问题了呢!

解决方案 »

  1.   


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    //.....其他的原来的代码
           <div>
                  <span>交易查询:</span> 
                  <span>
                        <input name="control_date" type="text" id="control_date" size="100" value="5,12,19,26"
                            maxlength="10" onclick="new BoxunDate().show(this);" readonly="readonly" />
                  </span>
           </div> 没问题啊,firefox,chrome,IE8-
      

  2.   


    我想应该是我的问题!我也试了一下!单独加上jquery后运行也是OK的!
    后来才知道是我项目里面另一个js的问题!
    我们用的DWZ的UI,不知道为什么,在var __ci = window.frames['__calendarIframe'];这句代码的时候
    __ci的结果为null。单独运行却又能得到结果!后来实在没办法,我就直接使用iframe了,这样就木有烦恼了!