2010-05-13 53 views
0

我在排除在IE中工作的網頁但在Firefox中工作時遇到問題。 Firefox的調試器停在下面一行:Javascript問題適用於IE而不適用於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 =新按鈕線,它進入nsSessionStore.js:

handleEvent: function sss_handleEvent(aEvent) { 

一旦退出這個功能,它沒有返回到JavaScript和下一行是永遠不會被調用,導致我認爲撥打新按鈕時出現問題。有誰知道我需要做什麼來解決這個問題?

+0

你會得到什麼錯誤? – SLaks 2010-05-13 20:25:43

+0

你的事件處理程序是完全錯誤的。 – SLaks 2010-05-13 20:26:24

+0

完全沒有錯誤 – 2010-05-13 20:26:34

回答

3

如果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()或某些其他形式的元素選擇。

相關問題