适用于IE而非Firefox的Javascript问题
我遇到了一个问题,当我对一个可以在IE中工作但不能在Firefox中工作的网页进行故障排除时。Firefox调试器正在以下行停止:适用于IE而非Firefox的Javascript问题,javascript,debugging,firefox,internet-explorer,Javascript,Debugging,Firefox,Internet Explorer,我遇到了一个问题,当我对一个可以在IE中工作但不能在Firefox中工作的网页进行故障排除时。Firefox调试器正在以下行停止: btnhelp = new button("btnhelp", framemenu.document.imghelp, "../images/gui/help_o.jpg", "../images/gui/help.jpg", "", "hand", true); 我看到button是在另一个类中定义的,有一些原型函数: function button(jscri
btnhelp = new button("btnhelp", framemenu.document.imghelp, "../images/gui/help_o.jpg", "../images/gui/help.jpg", "", "hand", true);
我看到button是在另一个类中定义的,有一些原型函数:
function button(jscriptname, htmlobj, dnimg, dimimg, action, cursor, enabled, hlimg)
{
//object for managing buttons easily
this.img = htmlobj;
if(htmlobj.name)
this.name = htmlobj.name
else if(htmlobj.id)
this.name = htmlobj.id
else
this.name = "error";
this.upimg = new Image();
this.dnimg = new Image();
this.dimimg = new Image();
this.hlimg = new Image();
this.upimg.src = this.img.src;
this.dnimg.src = dnimg;
this.dimimg.src = dimimg;
if(hlimg)
this.hlimg.src = hlimg;
this.action = action;
this.jscriptname = jscriptname;
if(cursor)
this.cursor = cursor;
else
this.cursor = "hand";
if(enabled)
this.enable();
else
this.disable();
this.img.onclick= new Function(this.jscriptname + ".click();");
this.img.onmouseover= new Function(this.jscriptname + ".mouseover();");
this.img.onmouseout= new Function(this.jscriptname + ".mouseout();");
}
button.prototype.enable = _enable;
button.prototype.disable = _disable;
button.prototype.mouseover = _mouseover;
button.prototype.mouseout = _mouseout;
button.prototype.click = _click;
button.prototype.hilight = _hilight;
function _enable()
{
this.img.src = this.upimg.src;
this.img.style.cursor = this.cursor;
this.enabled = true;
}
function _disable()
{
this.img.src = this.dimimg.src;
this.img.style.cursor = "default";
this.enabled = false;
}
function _hilight(bool)
{
this.img.src = this.hlimg.src;
this.enabled = bool;
}
function _mouseover()
{
if(this.enabled)
this.img.src = this.dnimg.src;
}
function _mouseout()
{
if(this.enabled)
{
this.img.src = this.upimg.src;
}
}
function _click()
{
if(this.enabled)
eval(this.action);
}
当调试器点击bthhelp=new按钮行时,它会转到nsSessionStore.js:
handleEvent: function sss_handleEvent(aEvent) {
一旦它退出这个函数,它就不会返回到JavaScript,下一行也不会被调用,这让我觉得调用一个新按钮有问题。有人知道我需要做些什么来解决这个问题吗?如果Firefox正在停止运行
btnhelp = new button("btnhelp", framemenu.document.imghelp, "../images/gui/help_o.jpg", "../images/gui/help.jpg", "", "hand", true);
唯一的潜在问题可能是按钮
尚未定义,或者framemenu.document.imghelp
存在问题。所有其他参数都是原语,所以我不明白为什么这些参数会有问题
我猜-,这几乎是任何人在没有更多信息的情况下都能给你的-,问题在于
framemenu
是文档中元素的ID,但实际上并没有定义为变量。Internet Explorer自动将具有有效id属性的所有元素注册为全局变量,可以从脚本访问这些全局变量,而无需使用document.getElementById()
。没有其他浏览器可以做到这一点,您必须使用document.getElementById()
或其他形式的元素选择。如果Firefox正在暂停
btnhelp = new button("btnhelp", framemenu.document.imghelp, "../images/gui/help_o.jpg", "../images/gui/help.jpg", "", "hand", true);
唯一的潜在问题可能是按钮
尚未定义,或者framemenu.document.imghelp
存在问题。所有其他参数都是原语,所以我不明白为什么这些参数会有问题
我猜-,这几乎是任何人在没有更多信息的情况下都能给你的-,问题在于
framemenu
是文档中元素的ID,但实际上并没有定义为变量。Internet Explorer自动将具有有效id属性的所有元素注册为全局变量,可以从脚本访问这些全局变量,而无需使用document.getElementById()
。没有其他浏览器可以这样做,您必须使用document.getElementById()
或其他形式的元素选择。您的事件处理程序完全错误。请注意,将默认光标(在else条件下)更改为this.cursor='pointer'代码>“hand”是专有的IE专用值,因此在Firefox/其他浏览器上无法工作。您的事件处理程序完全错误。请注意,将默认光标(在else条件下)更改为this.cursor='pointer'代码>“hand”是专有的IE专用值,因此在Firefox/其他浏览器上不起作用。