Przeszukaj pomoc

Unikaj oszustw związanych z pomocą.Nigdy nie będziemy prosić Cię o dzwonienie na numer telefonu, wysyłanie SMS-ów ani o udostępnianie danych osobowych. Zgłoś podejrzaną aktywność, korzystając z opcji „Zgłoś nadużycie”.

Więcej informacji

How do I get the displayed text of a label to change

  • 1 odpowiedź
  • 0 osób ma ten problem
  • 1 wyświetlenie
  • Ostatnia odpowiedź od cor-el

more options

Issue

I have another kind of problem with Firefox

Description

I have some code:

function ExpandCollapseAll(toggleElement) {

   var hideElement = "none";
   var showElement = "inline";
   var collapseAllImage = document.getElementById("collapseAllImage").getAttribute("src");
   var expandAllImage = document.getElementById("expandAllImage").getAttribute("src");
   var toggleAllLabel = document.getElementById("toggleAllLabel");
   var state = toggleElement.getAttribute("state");
   var collapseLabel = document.getElementById("collapseAllLabel").value;
   var expandLabel = document.getElementById("expandAllLabel").value;
   if(state  == "expanded")
   {
       toggleAllLabel.innerText = expandLabel;
       toggleElement.setAttribute("state", "collapsed");
       toggleElement.style.backgroundImage = "url(" + expandAllImage + ")";
   } else
   {
       toggleAllLabel.innerText = collapseLabel;
       toggleElement.setAttribute("state", "expanded");
       toggleElement.style.backgroundImage = "url(" + collapseAllImage + ")";
   }
   var elements = document.getElementsByTagName("div");
   for(var i = 0; i < elements.length; i++)
   {
       var elementClass = elements[i].getAttribute("class");
       var reg = new RegExp("^collapseableSection$|^collapseableSection\\s|\\scollapseableSection\\s|\\scollapseableSection$", "i");
       if(reg.test(elementClass))
       {
           if(state  == "expanded")
           {
               CollapseElement(elements[i]);
           } else
           {
               ExpandElement(elements[i]);
           }
       }
   } 

} This function gets called when a mouse click happens over the toggle element. The toggle element is a div which has a background-image, and the label I wish to change. As you can see, the div contains a state attribute that I use to decide which background-image and label to set. The background-image correctly gets changed/displayed when the div gets a click event. I have set alerts so I know that the innerText of the label is being set to the correct values. The problem is, the text being displayed never changes, EVER. This code works correctly for IE, Opera, and Safari. In each of those, the displayed text changes each time the div is clicked.



(Edited by Moderator: placed code in a CODE block - c)

This happened

Every time Firefox opened

The first time I opened the site

Troubleshooting information

 Application Basics
       Name
       Firefox
       Version
       3.6.3
       Profile Directory
         Open Containing Folder
       Installed Plugins
         about:plugins
       Build Configuration
         about:buildconfig
 Extensions
       Name
       Version
       Enabled
       ID
 Modified Preferences
     Name
     Value
       accessibility.browsewithcaret
       true
       accessibility.typeaheadfind.flashBar
       0
       browser.history_expire_days.mirror
       180
       browser.places.smartBookmarksVersion
       2
       browser.startup.homepage
       http://sharepoint/sites/uati/default.aspx
       browser.startup.homepage_override.mstone
       rv:1.9.2.3
       extensions.lastAppVersion
       3.6.3
       network.cookie.prefsMigrated
       true
       places.last_vacuum
       1274998179
       privacy.sanitize.migrateFx3Prefs
       true
       security.disable_button.openCertManager
       false

User Agent

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; InfoPath.3; .NET4.0C; .NET4.0E)

== Issue == I have another kind of problem with Firefox == Description == I have some code: <code>function ExpandCollapseAll(toggleElement) { var hideElement = "none"; var showElement = "inline"; var collapseAllImage = document.getElementById("collapseAllImage").getAttribute("src"); var expandAllImage = document.getElementById("expandAllImage").getAttribute("src"); var toggleAllLabel = document.getElementById("toggleAllLabel"); var state = toggleElement.getAttribute("state"); var collapseLabel = document.getElementById("collapseAllLabel").value; var expandLabel = document.getElementById("expandAllLabel").value; if(state == "expanded") { toggleAllLabel.innerText = expandLabel; toggleElement.setAttribute("state", "collapsed"); toggleElement.style.backgroundImage = "url(" + expandAllImage + ")"; } else { toggleAllLabel.innerText = collapseLabel; toggleElement.setAttribute("state", "expanded"); toggleElement.style.backgroundImage = "url(" + collapseAllImage + ")"; } var elements = document.getElementsByTagName("div"); for(var i = 0; i < elements.length; i++) { var elementClass = elements[i].getAttribute("class"); var reg = new RegExp("^collapseableSection$|^collapseableSection\\s|\\scollapseableSection\\s|\\scollapseableSection$", "i"); if(reg.test(elementClass)) { if(state == "expanded") { CollapseElement(elements[i]); } else { ExpandElement(elements[i]); } } } } </code> This function gets called when a mouse click happens over the toggle element. The toggle element is a div which has a background-image, and the label I wish to change. As you can see, the div contains a state attribute that I use to decide which background-image and label to set. The background-image correctly gets changed/displayed when the div gets a click event. I have set alerts so I know that the innerText of the label is being set to the correct values. The problem is, the text being displayed never changes, EVER. This code works correctly for IE, Opera, and Safari. In each of those, the displayed text changes each time the div is clicked. <br/> <br/>''(Edited by Moderator: placed code in a CODE block - c)''<br/> <br/> == This happened == Every time Firefox opened == The first time I opened the site == == Troubleshooting information == Application Basics Name Firefox Version 3.6.3 Profile Directory Open Containing Folder Installed Plugins about:plugins Build Configuration about:buildconfig Extensions Name Version Enabled ID Modified Preferences Name Value accessibility.browsewithcaret true accessibility.typeaheadfind.flashBar 0 browser.history_expire_days.mirror 180 browser.places.smartBookmarksVersion 2 browser.startup.homepage http://sharepoint/sites/uati/default.aspx browser.startup.homepage_override.mstone rv:1.9.2.3 extensions.lastAppVersion 3.6.3 network.cookie.prefsMigrated true places.last_vacuum 1274998179 privacy.sanitize.migrateFx3Prefs true security.disable_button.openCertManager false == User Agent == Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MS-RTC LM 8; InfoPath.3; .NET4.0C; .NET4.0E)

Wszystkie odpowiedzi (1)

more options

A good place to ask questions and 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.

See http://forums.mozillazine.org/viewforum.php?f=25