0

Possible Duplicate:
Javascript Error in FireFox Not in IE and Chrome

i have a JavaScript function which is in my Javacaleder.js file for Calender. This calender works fine in IE and chrome but not working in FF. It shows error in Error console.. " Event is not defined " It shows error in event.clientX; line below is the function..any help is appreciated.. below function is called like this...

 objDiv.style.left = GetControlLeftPosition_jScript() + "px";

function GetControlLeftPosition_jScript() {
var controlLeft = event.clientX;
var pageWidth = document.body.clientWidth;
var spaceinRight = parseInt(pageWidth) - parseInt(controlLeft);
if (spaceinRight > 220) {
    return controlLeft
}
else {
    return parseInt(pageWidth) - 220;
}

}

4

1 回答 1

1

用户单击文本框旁边的按钮,然后显示日历。好的。您的按钮单击处理程序将接收事件对象作为第一个参数。在那里,你有你的事件对象!

检查它是否undefined,如果是,您可能正在运行旧版本的 IE。在这种情况下,使用window.event

function buttonClickHandler(event) {
    var eventObj = event || window.event;
    objDiv.style.left = GetControlLeftPosition_jScript(eventObj) + "px";
}

function GetControlLeftPosition_jScript(eventObj) {
   var controlLeft = eventObj.clientX;
   //  ... remaining code.

也就是说,我建议您使用一个库来抽象这些问题,而是为您提供一个 api。像 jQuery 或 Mootools 或 dojo 或任何你喜欢的东西。

于 2012-07-03T10:51:51.073 回答