IE的占位符修复程序;t效果表单字段's值

Placeholder fix for IE that doesn't effect form field's value

本文关键字:字段 表单 占位符 IE 程序      更新时间:2023-09-26

我的web应用程序包含四个筛选表的表单字段。所有针对IE的HTML5占位符修复都将"占位符"替换为"值",并去掉模糊上的值。

不幸的是,在IE中,我的表单字段试图根据"占位符"修复来筛选表。

是否存在不影响实际字段值的占位符修复?

我推荐placeholder.js,它作为一个插件非常好。您可以将它包含在html中,并使用本地的html5占位符api。

我以前遇到过同样的问题,所以我自己做了后备

jsfiddle

  //place holder fallback 
  var testInput = document.createElement('input');
  var placeholderSupport = ("placeholder" in testInput);
if(!placeholderSupport){
    $('input[placeholder]').each(function (index, current) {
    var $real = $(this);
    var placeHolderValue = $real.attr("placeholder");
    var classes = $real.attr("class");
    $fakeInput = $("<input>").attr({"type": "text"}).val(placeHolderValue).addClass('placeholder fake-input' , classes );
    $fakeInput.insertBefore($real);
    $real.hide();
    $fakeInput.focus(function() {
      $(this).blur().hide()
      .next().show().focus();
    });
    $real.blur(function () {
      if ($(this).val() == '') {
        $(this).hide()
        .prev().show();
      }
    });
  });
}