0

these are the two functions (externally loaded):

function replaceText(element, text) {
    if (element != null) {
        clearText(element);
        var newNode = document.createTextNode(text);
        element.appendChild(newNode);
    }
}

function replaceImage(element, maker, imageState) {
    replaceText(element, "replacing image " + maker + " with " + imageState + " version");
    var imagePath = "_img/coffeeMaker_";
    if (maker != null)
    {
        document.getElementById("coffeeMakerImg"+ maker).src = imagePath + imageState + ".png";
    }
}

now here's the part that calls these functions. *notice that the replaceText() is called from within replaceImage()

replaceText(cmStatus_01, "BREWING " + name + "'s " + size + " " + beverage);
replaceImage("feedback", "01", "full");
document.forms[0].reset();

okay. now here's the kicker: the FIRST replaceText() works fine in ALL browsers. the replaceImage() fails ONLY in Firefox which CONTAINS A CALL TO replaceText() that only JUST worked as advertised!! i could see how i might have screwed up the image replacement (even though i copy/pasted it from another working project that DOES replace the image in FF...so weird...), but i do NOT see how the replaceText() can fail: it just worked!

so: whaaaaat!? i'm thinking its some kind of scope issue, but i'm stumped as to why.

totally stumped. forehead really sore...

thank for your time and help. i'm praying this isn't something really retarded...

WR!

PS: i'm also confused why, if i remove the quotes from the element name in the replaceImage() call, it breaks; but it works in the replaceText() call without brackets just fine...

4

1 回答 1

0

好的。我想到了。问题实际上是我传递给函数的内容:

cmStatus_01不是 div 的实际 ID。之前的评估是这样的:

var cmStatus_01 = document.getElementById('divName');

但我将 传递给divName函数replaceImage(),它期待它的评估版本,比如cmStatus_01. 所以它坏了。

因此,当我实际上重新设计了该功能时,我只是通过divName了,它显然有效。这是重组:

function replaceNodeText(id, newText)
{
    var node = document.getElementById(id);
    while (node.firstChild)
    {
        node.removeChild(node.firstChild);
    }
    node.appendChild(document.createTextNode(newText));
}

项目期限太紧了!它让我的大脑衰竭。:P

另外:很抱歉没有发布变量的来源。这将有很大帮助,我敢肯定,我不知道为什么我也不想发布它们。

感谢您的耐心和时间。

写!

于 2011-10-12T22:44:59.223 回答