有些JavaScript功能无法在Chrome浏览器上运行,为什么?

时间:2015-05-30 09:43:47

标签: 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浏览器中工作?

1 个答案:

答案 0 :(得分:1)

在上次bracket条件

中添加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>