js缺少对象是怎么回事?在asp.net中的textbox中点击显示日历控件,点击日历会将选中的日期填入textbox
Element.viewportOffset=function(forElement){varvalueT=0,valueL=0;varelement=forElemen...
Element.viewportOffset = function(forElement) {
var valueT = 0, valueL = 0;
var element = forElement;
do {
valueT += element.offsetTop || 0;
valueL += element.offsetLeft || 0;
// Safari fix
if (element.offsetParent == document.body &&
element.style['position'] == 'absolute') break;
} while (element = element.offsetParent);
element = forElement;
do {
if (!BrowserType.Opera || element.tagName == 'BODY') {
valueT -= element.scrollTop || 0;
valueL -= element.scrollLeft || 0;
}
} while (element = element.parentNode);
return Element._returnOffset(valueL, valueT);
};
Element._returnOffset = function(l, t) {
var result = [l, t];
result.left = l;
result.top = t;
return result;
};
var Event;
if(!Event){
Event = {};
}
Event.stop = function(e){
if(e.stopPropagation){
e.stopPropagation();
}else{
e.cancelBubble = true;
}
if(e.preventDefault){
e.preventDefault();
}else{
e.returnValue = false;
}
}
Event.addListener = function(target, eventType, handler, flag){
if(document.attachEvent){
target.attachEvent("on"+eventType, handler);
}else if(document.addEventListener){
target.addEventListener(eventType, handler, flag);
}else{
target["on"+eventType] = handler;
}
}
Event.removeListener = function(target, eventType, handler, flag){
if(document.detachEvent){
target.detachEvent("on"+eventType, handler);
}else if(document.removeEventListener){
target.removeEventListener(eventType, handler, flag);
}else{
target["on"+eventType] = null;
}
}
Event.target = function(el){
if(el.srcElement){
return el.srcElement;
}else{
return el.target;
}
}
function initLocation(){
var p = Element.viewportOffset(_target);
var pp = document.viewport.getScrollOffsets();
calendar.style.left = p.left+pp.left+"px";
var height = _target.clientHeight;
calendar.style.top = p.top +pp.top+ height+5 +"px";
}
calendar.style.top = p.top +pp.top+ height+5 +"px";还显示参数无效
调用时显示'null' 为空或不是对象
<script type="text/javascript" language="javascript" src="../../Styles/calendar.js"></script>
<script>
window.onload = function () {
c1 = new JSCalendar(document.getElementById("transdate1"));
// c2 = new JSCalendar(document.getElementById("transdate2"));
function format(date) {
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}
var dateEl = document.getElementById("transdate1")
dateEl.onDateChange = function (oldDate, newDate) {
}
// var dateEl1 = document.getElementById("transdate2")
// dateEl.onDateChange = function (oldDate, newDate) {
// }
}
<asp:TextBox ID="transdate1" runat="server"></asp:TextBox> 展开
var valueT = 0, valueL = 0;
var element = forElement;
do {
valueT += element.offsetTop || 0;
valueL += element.offsetLeft || 0;
// Safari fix
if (element.offsetParent == document.body &&
element.style['position'] == 'absolute') break;
} while (element = element.offsetParent);
element = forElement;
do {
if (!BrowserType.Opera || element.tagName == 'BODY') {
valueT -= element.scrollTop || 0;
valueL -= element.scrollLeft || 0;
}
} while (element = element.parentNode);
return Element._returnOffset(valueL, valueT);
};
Element._returnOffset = function(l, t) {
var result = [l, t];
result.left = l;
result.top = t;
return result;
};
var Event;
if(!Event){
Event = {};
}
Event.stop = function(e){
if(e.stopPropagation){
e.stopPropagation();
}else{
e.cancelBubble = true;
}
if(e.preventDefault){
e.preventDefault();
}else{
e.returnValue = false;
}
}
Event.addListener = function(target, eventType, handler, flag){
if(document.attachEvent){
target.attachEvent("on"+eventType, handler);
}else if(document.addEventListener){
target.addEventListener(eventType, handler, flag);
}else{
target["on"+eventType] = handler;
}
}
Event.removeListener = function(target, eventType, handler, flag){
if(document.detachEvent){
target.detachEvent("on"+eventType, handler);
}else if(document.removeEventListener){
target.removeEventListener(eventType, handler, flag);
}else{
target["on"+eventType] = null;
}
}
Event.target = function(el){
if(el.srcElement){
return el.srcElement;
}else{
return el.target;
}
}
function initLocation(){
var p = Element.viewportOffset(_target);
var pp = document.viewport.getScrollOffsets();
calendar.style.left = p.left+pp.left+"px";
var height = _target.clientHeight;
calendar.style.top = p.top +pp.top+ height+5 +"px";
}
calendar.style.top = p.top +pp.top+ height+5 +"px";还显示参数无效
调用时显示'null' 为空或不是对象
<script type="text/javascript" language="javascript" src="../../Styles/calendar.js"></script>
<script>
window.onload = function () {
c1 = new JSCalendar(document.getElementById("transdate1"));
// c2 = new JSCalendar(document.getElementById("transdate2"));
function format(date) {
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}
var dateEl = document.getElementById("transdate1")
dateEl.onDateChange = function (oldDate, newDate) {
}
// var dateEl1 = document.getElementById("transdate2")
// dateEl.onDateChange = function (oldDate, newDate) {
// }
}
<asp:TextBox ID="transdate1" runat="server"></asp:TextBox> 展开
4个回答
展开全部
如果用了母版页的话,就要取ClientID,代码太长,本人没时间细看!不然,追问就好了~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用的是calendar日历控件的话应该引用WdatePicker.js文件而不是calendar.js
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<asp:TextBox ID="transdate1" runat="server"></asp:TextBox>都没有调用js怎么能实现啊?
追问
var dateEl = document.getElementById("transdate1")通过这个来获取的不对吗?
追答
你不是想点击textbox显示出来日立控件吗?但是你textbox都没有调用js怎么能实现那?在textbox中添加点击事件,让他调用js,来实现显示日历,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询