0

我在 javascript 中有一些简单的函数,它们在除 IE9 之外的大多数浏览器中都能正常工作。我听说 Ie9 对逗号等很挑剔。但我找不到任何明显的问题。你们中的任何人都可以解释一下吗?完整代码如下

    <script type="text/javascript">

      document.addEventListener("DOMContentLoaded", load, false);


      function load() {
        //dom loaded


        var elUserId = document.getElementById("user_id"); 
        var elPasswordId = document.getElementById("password");
        var elLoginMsg = document.getElementById("usernameMsg");
        var elPasswordMsg = document.getElementById("passwordMsg");
        var elIncreaseFontSize = document.getElementById("increaseFont");
        var elResetFontSize = document.getElementById("resetFont");
        var elChangeContrast = document.getElementById("changeContrast");
        var elResetContrast = document.getElementById("resetContrast");
        var logInbox = document.getElementById("loginBox");
        var helpWithBB = document.getElementById("helpWithBB");
        var fontUp = '135%';
        var fontReset = '100%';
        var black = '#000000';
        var white = '#ffffff';
        var divReset ='415px';
        var divChange ='525px';
        var txtSizeChange ='40.5em';
        var txtReset ='42em';


        elLoginMsg.style.display ='none';
        elPasswordMsg.style.display = 'none';

        elPasswordId.addEventListener("focus", function(){
            showText(elPasswordMsg);
        }, false);

        elUserId.addEventListener("click", function(){
            showText(elLoginMsg);
        }, false);

        elResetFontSize.addEventListener("click", function(){
        //pass size change and element affected to be manipulated
        //resetTextSize(fontReset,logInbox,elPasswordMsg);
        changeTextSize(fontReset,logInbox,elPasswordMsg,divReset,txtReset);
        });

        elChangeContrast.addEventListener("click", function(){
        //pass size change and element affected to be manipulated
        changeContrast(logInbox, helpWithBB, black, white);
        });

        elResetContrast.addEventListener("click", function(){
        document.location.reload(true);
        });



        elIncreaseFontSize.addEventListener("click", function(){
        //pass size change and element affected to be manipulated
        changeTextSize(fontUp,logInbox,elPasswordMsg,divChange,txtSizeChange);
        });


        function changeContrast(mainDiv, secDiv, txtColor, bkColor){

        secDiv.style.background = bkColor;
        mainDiv.style.background = bkColor;

        showText(elPasswordMsg);
        showText(elLoginMsg);

        elLoginMsg.style.color = txtColor;
        elPasswordMsg.style.color = txtColor;

            var anchors = document.getElementsByTagName('a');
            for(var i = 0; i < anchors.length; i++) {
            anchors[i].style.color = txtColor;
            }

            var para = document.getElementsByTagName('p');
            for(var i = 0; i < anchors.length; i++) {
            para[i].style.color = txtColor;
            }
        }

        function changeTextSize(fontUp, elDiv, msg, divH, msgT){
        document.body.style.fontSize=fontUp;
        elDiv.style.height = divH;
        msg.style.top = msgT;
        }

        function showText(id){
            id.style.display ='block';
        }

      }

    </script> 
4

1 回答 1

0

useCapture在某些调用中缺少第三个参数 ( ),addEventListener()但除此之外没有任何明显错误。我知道 FirefoxaddEventListener()在去年才开始支持没有第三个参数,所以 IE 9 可能不支持它。

更新

这个理论就这么多。IE 9 中的两个参数似乎很好:http: //jsfiddle.net/xZRy7/

于 2012-10-05T08:52:37.007 回答