繁体   English   中英

在IE和Firefox中无法使用的Javascript问题

[英]Javascript issue that works in IE and not Firefox

在对可在IE中但不能在Firefox中运行的网页进行故障排除时,我遇到了一个问题。 Firefox调试器在以下行停止:

btnhelp = new button("btnhelp", framemenu.document.imghelp, "../images/gui/help_o.jpg", "../images/gui/help.jpg", "", "hand", true);

我看到在另一个类中定义了一些原型函数的按钮是这样的:

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);

唯一潜在的问题可能是尚未定义button或者是framemenu.document.imghelp出现问题。 所有其他参数都是基元,因此我看不到为什么其中任何一个都有问题。

我猜想-这几乎是任何人在没有更多信息的情况下都能给您的信息-问题是framemenu是文档中元素的ID,但实际上没有定义为变量。 Internet Explorer会自动将具有有效id属性的所有元素注册为全局变量,而无需使用document.getElementById()即可从脚本进行访问。 没有其他浏览器可以做到这一点,您必须使用document.getElementById()或其他某种形式的元素选择。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM