javascript - 某些 JavaScript 函数在 Chrome 浏览器上不起作用,为什么?

标签 javascript php codeigniter

我开发了一个 JavaScript 函数来隐藏和显示我的文本框。此功能在 Mozilla 中运行良好,但在 Chrome 浏览器中运行不佳。我不知道为什么。我的功能:

function selectType()
{   if(document.getElementById("promotype").value=="Amount")
    {   document.getElementById("typediv").style.display = "none";
        document.getElementById("type").value = 'amount';
    }
    if(document.getElementById("promotype").value=="Percentage")
    {   document.getElementById("typediv").style.display = "none";
        document.getElementById("type").value = 'percentage';
    }

    if(document.getElementById("promotype").value=="Freesignup")
    {   document.getElementById("amount").style.display = "block";
        document.getElementById("typediv").style.display = "block";
    }
    else if(document.getElementById("promotype").value=="Gift cards")
    {   document.getElementById("amount").style.display = "block";
        document.getElementById("selectmemberdiv").style.display = "block";
        document.getElementById("typediv").style.display = "block";
    }
    else
    {   if(document.getElementById("promotype").value=="Freeride")
        {   document.getElementById("amount").style.display = "none";
            document.getElementById("type").value = 'none';
            document.getElementById("typediv").style.display = "none";
        }
        else
           document.getElementById("amount").style.display = "block";    
        document.getElementById("selectmemberdiv").style.display = "none";
    }
}

首先,当我的页面加载时,我将隐藏我的“金额”文本框,之后我会根据类别单击下拉菜单以显示我的金额文本框。

但为什么它们在 Chrome 浏览器中不起作用?

最佳答案

在最后的else条件中添加括号

<script>
    function selectType()
    {
        if (document.getElementById("promotype").value == "Amount")
        {
            document.getElementById("typediv").style.display = "none";
            document.getElementById("type").value = 'amount';
        }
        if (document.getElementById("promotype").value == "Percentage")
        {
            document.getElementById("typediv").style.display = "none";
            document.getElementById("type").value = 'percentage';
        }

        if (document.getElementById("promotype").value == "Freesignup")
        {
            document.getElementById("amount").style.display = "block";
            document.getElementById("typediv").style.display = "block";
        }
        else if (document.getElementById("promotype").value == "Gift cards")
        {
            document.getElementById("amount").style.display = "block";
            document.getElementById("selectmemberdiv").style.display = "block";
            document.getElementById("typediv").style.display = "block";
        }
        else
        {
            if (document.getElementById("promotype").value == "Freeride")
            {
                document.getElementById("amount").style.display = "none";
                document.getElementById("type").value = 'none';
                document.getElementById("typediv").style.display = "none";
            }
            else
            {// this bracket
                document.getElementById("amount").style.display = "block";
                document.getElementById("selectmemberdiv").style.display = "none";
            }// end else condition
        }
    }

</script>

关于javascript - 某些 JavaScript 函数在 Chrome 浏览器上不起作用,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30544600/

相关文章:

php - 无法插入数据库 codeigniter 但可以更新

javascript - 如果使用 Passport js 用户登录/身份验证失败,Jquery 警告框

javascript - NodeJS/jQuery - 投票通知 API

javascript - 我应该如何对有很多重叠的代码进行单元测试?

php - Google 日历列表事件方法不返回任何事件

mysql - 与 codeigniter 中的不同和相似

javascript - Google Visualization 的 ZoomLevel 参数不起作用

javascript - 如何将单击的链接的值传递到另一个页面并在跨度中显示它

php - 如何在symfony2中添加自己的自定义服务容器标签,以及如何获取标签服务?

php - 如何在 CodeIgniter 中访问静态资源?