X
點擊此處開啟此網站的行動版。

技術支援討論區

Firefox resets Javascript's variable's value

已張貼

I'm using an onload eventlistener to call a script which increases the value of a variable. I need to get the variable's value before I increase it. Safari and Chrome (Webkit) give the right result but Firefox always alerts "0"... To be clear: Firefox also alerts "done" which means it gets the job done but it does NOT alert the right value before I increase it!


This is my Script:

var obj = {

   build: function() {
       var progressCount = 0; 
       var otherFunction = function(number) {
               alert(number);
       } ;
       var finalFunction = function() {
               alert("done");
       } ;
       var progress = function() {
               alert(progressCount);  // very important line!
               progressCount++;
               otherFunction(progressCount);
               if (progressCount == ARRAY.length) {
               finalFunction();
               }
       };
       ARRAY=document.getElementsByClassName("picture");
       for (var i = 0; i < ARRAY.length; i++)
       ARRAY[i].addEventListener("load", progress);
   }

}

obj.build();


What else could I try? Thank you very much!

I'm using an onload eventlistener to call a script which increases the value of a variable. I need to get the variable's value before I increase it. Safari and Chrome (Webkit) give the right result but Firefox always alerts "0"... To be clear: Firefox also alerts "done" which means it gets the job done but it does NOT alert the right value before I increase it! This is my Script: var obj = { build: function() { var progressCount = 0; var otherFunction = function(number) { alert(number); } ; var finalFunction = function() { alert("done"); } ; var progress = function() { alert(progressCount); // very important line! progressCount++; otherFunction(progressCount); if (progressCount == ARRAY.length) { finalFunction(); } }; ARRAY=document.getElementsByClassName("picture"); for (var i = 0; i < ARRAY.length; i++) ARRAY[i].addEventListener("load", progress); } } obj.build(); What else could I try? Thank you very much!

由 basbebe 於 修改

額外的系統細節

應用程式

  • User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17

更多資訊

Allgemeine Informationen
Name
Firefox
Version
17.0
User-Agent
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/17.0 Firefox/17.0
Profilordner
Im Finder anzeigen
Aktivierte Plugins
about:plugins
Build-Konfiguration
about:buildconfig
Absturzberichte
about:crashes
Speicherverwendung
about:memory
Erweiterungen
Name
Version
Aktiviert
ID
Adobe Acrobat - Create PDF
2.0
false
web2pdfextension@web2pdf.adobedotcom
Wichtige modifizierte Einstellungen
Name
Wert
accessibility.typeaheadfind.flashBar
0
browser.cache.disk.capacity
358400
browser.cache.disk.smart_size.first_run
false
browser.cache.disk.smart_size.use_old_max
false
browser.cache.disk.smart_size_cached_value
358400
browser.places.smartBookmarksVersion
4
browser.startup.homepage
http://digiflow1.w-co.com/
browser.startup.homepage_override.buildID
20121119183901
browser.startup.homepage_override.mstone
17.0
extensions.lastAppVersion
17.0
gfx.blacklist.webgl.msaa
4
network.cookie.prefsMigrated
true
places.database.lastMaintenance
1352718897
places.history.expiration.transient_current_max_pages
104858
privacy.cpd.cookies
false
privacy.cpd.downloads
false
privacy.cpd.formdata
false
privacy.cpd.history
false
privacy.cpd.sessions
false
privacy.sanitize.migrateFx3Prefs
true
privacy.sanitize.timeSpan
0
Grafik
Vendor-ID
0x8086
Geräte-ID
0x 166
WebGL-Renderer
NVIDIA Corporation -- NVIDIA GeForce GT 650M OpenGL Engine -- 2.1 NVIDIA-8.6.22
GPU-beschleunigte Fenster
1/1 OpenGL
AzureCanvasBackend
quartz
AzureFallbackCanvasBackend
none
AzureContentBackend
none
JavaScript
Inkrementelle GC
1
Barrierefreiheit
Aktiviert
0
Barrierefreiheit verhindern
0
Bibliotheken-Versionen
Minimal vorausgesetzte Version
Verwendete Version
NSPR
4.9.2
4.9.2
NSS
3.13.6.0 Basic ECC
3.13.6.0 Basic ECC
NSS Util
3.13.6.0
3.13.6.0
NSS SSL
3.13.6.0 Basic ECC
3.13.6.0 Basic ECC
NSS S/MIME
3.13.6.0 Basic ECC
3.13.6.0 Basic ECC

cor-el
  • Top 10 Contributor
  • Moderator
17418 個解決方法 157376 個答案

A good place to ask advice about web development is at the MozillaZine "Web Development/Standards Evangelism" forum.

The helpers at that forum are more knowledgeable about web development issues.
You need to register at the MozillaZine forum site in order to post at that forum.

A good place to ask advice about web development is at the MozillaZine "Web Development/Standards Evangelism" forum. *http://forums.mozillazine.org/viewforum.php?f=25 The helpers at that forum are more knowledgeable about web development issues.<br> You need to register at the MozillaZine forum site in order to post at that forum.