2013-11-01 102 views
0

我才知道,jquery supports all including old browsersjQuery的跨浏览器支持问题

但我尝试添加一个占位符的搜索框,它不是在IE8

工作
jQuery(document).ready(function(){ 
    $('#search').attr('placeholder','search....');       
}); 

所以我想更多地了解跨浏览器支持。如所说的那样,它实际上还是不工作?


我知道HTML属性placeholder不支持。但我的问题是关于jQuery。

+0

IE8以下

<input type="text" value="search..." onfocus="if(this.value == 'search...') this.value = '';" onblur="if(this.value == '') this.value = 'search...';" /> 

??用火杀死它 !! :p – coolguy

+0

您似乎滥用占位符属性来替代'

+0

我似乎假设jquery使用自己的定义超出了html,但有这个问题来了解jquery只是解析dom ...... –

回答

1

由于不支持以上占位符。
因此,将以下代码/注释添加到HTML页面的头部。现在ie8会很好地发挥。

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> 
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
<!--[if lt IE 9]> 
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
<![endif]--> 
+0

什么是HTML5 Shim和Respond.js?请简要讨论一下HTML5 Shim和Respond.js,以及何时需要这2个?谢谢 – Mou

2

占位符是未通过IE8

使用支持的HTML5特征使用jquery

<input type="text" class="my-input" value="" /> 

    <script type="text/javascript"> 

     $(document).ready(function() { 
      $('.my-input').val('search...'); 
      $('.my-input').focus(function() { 
       if (this.value == 'search...') this.value = ''; 
      }); 
      $('input.my-input').blur(function() { 
       if (this.value == '') this.value = 'search...' 
      }); 
     }); 
     /* 
     here I assumed a class 
     .my-input 

     you can use input#id or input.className or other selector 

     better you give the code of your text-box or entire form so that I can give you the exact selector 

     */ 
    </script> 
+0

我怎么能做到这一点与jquery因为我不能编辑标记 –