IE8下,采用bootstrap中的时间插件

来源:互联网 发布:美图看看 mac 编辑:程序博客网 时间:2024/05/21 17:05

在IE8下,采用时间插件,发现,点击展示出来的时间不是当前对应的年份,但是在非IE浏览器系都没有问题,发现时间没有正确展示的原因是因为IE8不支持placeholder属性,并且会把placeholder属性中的值当成value值传递;


而时间插件是会工具当前的value值进行展示当前与附近的年份值,所以导致IE8下年份展示不正确,解决方法:

在点击事件中先判断对应value是对应placeholder的值还是正常的value值,如果为placeholder值,清空value


//时间bothyear
$("#bothyear").on('click',function(){
      $("#bothyear").focus();
 })
$("#bothyear").focus(function(){

    if( !('placeholder' in document.createElement('input')) ){   
if($("#bothyear").val() == '出生年份'){
          $("#bothyear").val("");
        }
      }
    $("#bothyear").datetimepicker({
language:'zh-CN',
format: 'yyyy',
autoclose:true,
minView:4,
startView:4,
maxView:4

 });
})
$("#bothyear").blur(function(){
if( !('placeholder' in document.createElement('input')) ){ 
       if($("#bothyear").val() == ''){
         $("#bothyear").val("出生年份");
      }
      }
    })

0 0
原创粉丝点击