为了账号安全,请及时绑定邮箱和手机立即绑定

如何在IE8和9中支持占位符属性

如何在IE8和9中支持占位符属性

MMTTMM 2019-10-17 14:08:50
我有一个小问题,placeholderIE 8-9不支持输入框的属性。在我的项目(ASP Net)中获得这种支持的最佳方法是什么。我正在使用jQuery。我需要使用其他一些外部工具吗?是http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html好的解决办法?
查看完整描述

3 回答

?
绝地无双

TA贡献1946条经验 获得超4个赞

在$ .Browser.msie是不是最新的JQuery了...你必须使用$。支持


如下所示:


 <script>


     (function ($) {

         $.support.placeholder = ('placeholder' in document.createElement('input'));

     })(jQuery);



     //fix for IE7 and IE8

     $(function () {

         if (!$.support.placeholder) {

             $("[placeholder]").focus(function () {

                 if ($(this).val() == $(this).attr("placeholder")) $(this).val("");

             }).blur(function () {

                 if ($(this).val() == "") $(this).val($(this).attr("placeholder"));

             }).blur();


             $("[placeholder]").parents("form").submit(function () {

                 $(this).find('[placeholder]').each(function() {

                     if ($(this).val() == $(this).attr("placeholder")) {

                         $(this).val("");

                     }

                 });

             });

         }

     });

 </script>


查看完整回答
反对 回复 2019-10-17
  • 3 回答
  • 0 关注
  • 538 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信