簡體   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