angular 1.2版本兼容ie8

2018-09-12  本文已影响0人  清汤饺子

1、html的title中加入如下meta:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

2、引入js:

 <!--[if IE 8]>
<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.5/es5-shim.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
</style>
<![endif]-->

这个ie8的兼容版解决了很多AngularJS在IE8中的兼容问题,但是在IE8下的兼容依然会存在一些问题,比如文字图标在IE8中使用的时候会存在需要反流才能显示的情况,很多基于AngularJS的组件在IE8下的异常等等。

3、自定义指令

4、html加入id="ng-app"

<html lang="zh-CN" xmlns:ng="http://angularjs.org" id="ng-app" ng-app="AuthenticationApp">

5.placeholder的问题

6.如果还是不行。看下ie的控制台报什么错,再去对照修改,比如只能var 定义变量,不支持string.split()方法等。如果有引用都会报错


image
placeholder.js

$(function(){
//判断浏览器是否支持placeholder属性
supportPlaceholder='placeholder'in document.createElement('input');

placeholder=function(input){

    var text = input.attr('placeholder');
    defaultValue = input.defaultValue;

    if(!defaultValue){

        input.val(text).addClass("phcolor");
    }

    input.focus(function(){

        if(input.val() == text){

            $(this).val("");
        }
    })


    input.blur(function(){

        if(input.val() == ""){

            $(this).val(text).addClass("phcolor");
        }
    });

    //输入的字符不为灰色
    input.keydown(function(){

        $(this).removeClass("phcolor");
    })
}

//当浏览器不支持placeholder属性时,调用placeholder函数
if(!supportPlaceholder){

    $('input').each(function(){

        text = $(this).attr("placeholder");

        if($(this).attr("type") == "text"){

            placeholder($(this));
        }
    })
}
});
上一篇 下一篇

猜你喜欢

热点阅读