<tfoot id='cs7Bt'></tfoot>

  1. <i id='cs7Bt'><tr id='cs7Bt'><dt id='cs7Bt'><q id='cs7Bt'><span id='cs7Bt'><b id='cs7Bt'><form id='cs7Bt'><ins id='cs7Bt'></ins><ul id='cs7Bt'></ul><sub id='cs7Bt'></sub></form><legend id='cs7Bt'></legend><bdo id='cs7Bt'><pre id='cs7Bt'><center id='cs7Bt'></center></pre></bdo></b><th id='cs7Bt'></th></span></q></dt></tr></i><div id='cs7Bt'><tfoot id='cs7Bt'></tfoot><dl id='cs7Bt'><fieldset id='cs7Bt'></fieldset></dl></div>

      <bdo id='cs7Bt'></bdo><ul id='cs7Bt'></ul>

      <small id='cs7Bt'></small><noframes id='cs7Bt'>

    1. <legend id='cs7Bt'><style id='cs7Bt'><dir id='cs7Bt'><q id='cs7Bt'></q></dir></style></legend>
    2. JavaScript在IE和FF下的兼容性问题

      JavaScript在不同浏览器下存在着兼容性问题,主要是由于浏览器厂商对于JavaScript规范的实现存在差异。其中,IE与Firefox是JavaScript最常用的两个浏览器,就其在两者下的兼容性问题,本文将提供完整攻略,帮助我们解决问题。
    3. <small id='9g0ih'></small><noframes id='9g0ih'>

      <tfoot id='9g0ih'></tfoot>
        <tbody id='9g0ih'></tbody>

              <bdo id='9g0ih'></bdo><ul id='9g0ih'></ul>

                <i id='9g0ih'><tr id='9g0ih'><dt id='9g0ih'><q id='9g0ih'><span id='9g0ih'><b id='9g0ih'><form id='9g0ih'><ins id='9g0ih'></ins><ul id='9g0ih'></ul><sub id='9g0ih'></sub></form><legend id='9g0ih'></legend><bdo id='9g0ih'><pre id='9g0ih'><center id='9g0ih'></center></pre></bdo></b><th id='9g0ih'></th></span></q></dt></tr></i><div id='9g0ih'><tfoot id='9g0ih'></tfoot><dl id='9g0ih'><fieldset id='9g0ih'></fieldset></dl></div>
              • <legend id='9g0ih'><style id='9g0ih'><dir id='9g0ih'><q id='9g0ih'></q></dir></style></legend>

                JavaScript在不同浏览器下存在着兼容性问题,主要是由于浏览器厂商对于JavaScript规范的实现存在差异。其中,IE与Firefox是JavaScript最常用的两个浏览器,就其在两者下的兼容性问题,本文将提供完整攻略,帮助我们解决问题。

                1.常见的兼容性问题

                在IE和Firefox中,常见的JavaScript兼容性问题如下:

                • DOM元素属性的设置
                • 事件绑定方式
                • XMLHttpRequest对象的创建方式
                • 本地存储对象的使用方式
                • 对象方法的支持程度

                2.解决方案

                针对上述问题,我们可以采用以下解决方案:

                2.1 DOM元素属性的设置

                在IE浏览器下,设置DOM元素属性方式如下:

                document.getElementById('myId').innerText='new text';
                

                在Firefox浏览器下,设置DOM元素属性方式如下:

                document.getElementById('myId').textContent='new text';
                

                因此,我们可以采用以下方式解决:

                var element = document.getElementById('myId');
                if (element.innerText) {
                    element.innerText = 'new text';
                } else {
                    element.textContent = 'new text';
                }
                

                2.2 事件绑定方式

                在IE浏览器下,绑定事件方式如下:

                var element = document.getElementById('myId');
                element.attachEvent('onclick', function() {
                    //perform action
                });
                

                在Firefox浏览器下,绑定事件方式如下:

                var element = document.getElementById('myId');
                element.addEventListener('click', function() {
                    //perform action
                }, false);
                

                因此,我们可以采用以下方式解决:

                var element = document.getElementById('myId');
                if (element.attachEvent) {
                    element.attachEvent('onclick', function() {
                        //perform action
                    });
                } else {
                    element.addEventListener('click', function() {
                        //perform action
                    }, false);
                }
                

                3.示例说明

                以下是两条典型的兼容性示例:

                3.1 对象方法的支持程度

                在IE浏览器下,不支持indexOf()方法,我们可以通过以下代码检测是否支持该方法:

                if (!Array.prototype.indexOf) {
                    Array.prototype.indexOf = function(item) {
                        var result = -1;
                        for (var i = 0, len = this.length; i < len; i++) {
                            if (this[i] === item) {
                                result = i;
                                break;
                            }
                       }
                       return result;
                    }
                }
                

                在Firefox浏览器下不需要这段代码,因为Firefox浏览器默认支持indexOf()方法。

                3.2 XMLHttpRequest对象的创建方式

                在IE浏览器下,创建XMLHttpRequest对象需要使用ActiveXObject方式,我们可以通过以下代码实现:

                var xmlhttp;
                if (window.XMLHttpRequest) {
                    xmlhttp=new XMLHttpRequest();
                } else if (window.ActiveXObject) {
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                

                在Firefox浏览器下不需要这段代码,因为Firefox浏览器默认支持XMLHttpRequest对象。

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                下面是“背景图片自适应浏览器分辨率大小并自动拉伸全屏”的完整攻略。
                下面是详细讲解“简单但很实用的5个CSS属性”的完整攻略:
                以下是兼做美工之导航条制作过程分享的完整攻略:
                JS 控制 CSS 样式表的方式主要有两种:通过修改样式属性来修改元素样式,以及通过切换 CSS 类名来切换元素样式。下面分别给出具体的步骤和示例说明。
                实现首页动态视频背景,可以使用HTML5的video标签,下面是具体的示例代码和操作步骤:
              • <small id='fIn2a'></small><noframes id='fIn2a'>

                <i id='fIn2a'><tr id='fIn2a'><dt id='fIn2a'><q id='fIn2a'><span id='fIn2a'><b id='fIn2a'><form id='fIn2a'><ins id='fIn2a'></ins><ul id='fIn2a'></ul><sub id='fIn2a'></sub></form><legend id='fIn2a'></legend><bdo id='fIn2a'><pre id='fIn2a'><center id='fIn2a'></center></pre></bdo></b><th id='fIn2a'></th></span></q></dt></tr></i><div id='fIn2a'><tfoot id='fIn2a'></tfoot><dl id='fIn2a'><fieldset id='fIn2a'></fieldset></dl></div>
                <legend id='fIn2a'><style id='fIn2a'><dir id='fIn2a'><q id='fIn2a'></q></dir></style></legend>
                <tfoot id='fIn2a'></tfoot>
                    <tbody id='fIn2a'></tbody>
                  • <bdo id='fIn2a'></bdo><ul id='fIn2a'></ul>