javascript - 这个 javascript if 语句有什么问题

标签 javascript

用于显示/隐藏选项卡和 iFrame 的 JavaScript 函数:

function ChangeStep(id)
{
    var i = 1;
    // hide all other tabs:
    while(i<3) {
        var divID = 'tabs' + i;
        if (divID !== null) {
            document.getElementById(divID).className = " hide";
        }
        i++;
    }

    // show this one
    document.getElementById(id).className = " show";
}

if (id == "tab2") {
    document.getElementById(iFrame).className = " iFrame2";
}
else if (id == "tab1") {
    document.getElementById(iFrame).className = " iFrame1";
}

选项卡的更改有效,但底部的 if 语句似乎不起作用。

编辑

问题是我有一个 ID 为 'iFrame' 的 iFrame。 现在,我在 css 文件中创建了 2 个类,名为:'iFrame1''iFrame2',它们具有不同的设置,使 iFrame 看起来不同。 上面的函数在更改'选项卡'时没有问题(将“显示”类添加到一个选项卡,将“隐藏”类添加到所有其他选项卡)。 但它似乎没有将 iFrames 类更改为 'iFrame2' 和/或 'iFrame1' 我无法将其放在 JSFiddle 上,因为我的网站严重依赖图像,因此我将直接将您链接到我上传的位置:www.FeedtheSyrians.com

最佳答案

您的 if 语句不在函数体内,这意味着调用函数时不会执行它。

不知道什么时候执行。我不是 JS 专家,我不想做出(受过教育的)猜测,也许有更多知识的人可以说。

关于javascript - 这个 javascript if 语句有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16888313/

相关文章:

javascript - Highchart 标签旋转使我的专栏消失

javascript - 将 json 模式转换为 Angular 树控制树模型

javascript - 通过 Javascript 在 HTML 页面上使用 YouTube API

javascript - Modernizr.load 的使用

javascript - Typeahead.js 建议未被过滤

javascript - 无法让我的 "hello world"YUI asyncRequest javascript 运行,并且出于某种原因我无法使用调试器(chrome 或 fb)跟踪执行

javascript - 当我的应用程序包含查询字符串时,如何使用 OneDrive Web 选择器

javascript - 用于获取所有下拉列表值的 Jquery 选择器,2 个下拉列表的问题

javascript - 停止链接重定向jquery

php - 创建元素在 jquery 1.8.3 中不起作用