日期:2014-05-18  浏览次数:21070 次

日历控件导致textbox的onblur事件和TextChanged事件不执行
我在网页里放了个textbox,
<asp:TextBox ID="txtSdate" runat="server" onclick="SelectDate(this.name)" AutoPostBack="True" ontextchanged="txtSdate_TextChanged" OnBlur="refreshclick()" ></asp:TextBox>

用SelectDate(this.name)调用下面的js,来达到日历控件的目的,我想在选定日期后自动去刷新页面,也就是调用
ontextchanged="txtSdate_TextChanged",但是这样的效果是,不行将鼠标点在textbox里然后敲一下回车才能刷新
我又加了OnBlur="refreshclick()" ,选好日期后,在textbox外点一下鼠标,onblur事件同样不执行。

我看了下js文件,发现他是生成的div,也就是说选好日期后,txtSdate的Text并没有变,所以ontextchanged事件不执行吗?
有没有办法实现选点日期后自动调用ontextchanged或者OnBlur事件呢?


下面是生成日历的js文件,麻烦高手帮忙看看,谢谢!
var cal;
var isFocus=false; 
function SelectDate(o,p,strFormat)
{
  var date = new Date();
  //alert(date);
  var by = date.getFullYear() - 50;
  // alert(by);
  var ey = date.getFullYear() + 50;
  // alert(ey);
  var obj = document.getElementById(o);
  // alert(o);
  cal = (cal == null) ? new Calendar(by, ey, 0) : cal;
  // alert(cal);
  if(arguments.length > 2&&strFormat!=null)
  {
  cal.dateFormatStyle = strFormat;
  // alert(strFormat);
  // alert(cal.dateFormatStyle);
  }
   
  if(arguments.length == 1)
  {
  cal.show(obj);
  // alert(obj);
  }
  else
  {
  var pop = document.getElementById(p);
  cal.show(obj, pop);
  // alert(pop);
  }
}
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);
  if (isNaN(y)) y = new Date().getFullYear();
  if (isNaN(m)) m = new Date().getMonth();
  if (isNaN(d)) d = new Date().getDate();
  var dt;
  eval("dt = new Date('" + y + "', '" + (m - 1) + "','" + d + "')");
  return dt;
  // alert(dt);
}
Date.prototype.format = function(style) {
  var o = {
  "M+" : this.getMonth() + 1, 
  "d+" : this.getDate(),  
  "h+" : this.getHours(),  
  "m+" : this.getMinutes(),  
  "s+" : this.getSeconds(),  
  "w+" : "天一二三四五六".charAt(this.getDay()),  
  "q+" : Math.floor((this.getMonth() + 3) / 3),  
  "S" : this.getMilliseconds() 
  }
  if(/(y+)/.test(style)) {
  style = style.replace(RegExp.$1,
  (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  }
  for(var k in o){
  if(new RegExp("("+ k +")").test(style)){
  style = style.replace(RegExp.$1,
  RegExp.$1.length == 1 ? o[k] :
  ("00" + o[k]).substr(("" + o[k]).length));
  }
  }
  return style;
};
function Calendar(beginYear, endYear, lang, dateFormatStyle) {
  this.beginYear = 1990;
  this.endYear = 2010;
  this.lang = 0;  
  this.dateFormatStyle = "yyyy-MM-dd";

  if (beginYear != null && endYear != null){
  this.beginYear = beginYear