javascript - 占位符显示为点状而不是占位符文本(默认文本)

标签 javascript jquery html css

Placeholder 在 IE10 以下的浏览器中不工作,同时我写了下面的代码它工作正常。 但问题出在密码字段中,它显示的是点而不是占位符文本。请找到随附的屏幕截图。 这是我的代码,请问有没有修复密码字段占位符可见的解决方案。

//Default text in login page.
(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("login").submit(function () {
            $(this).find('[placeholder]').each(function() {
                if ($(this).val() == $(this).attr("placeholder")) {
                    $(this).val("");
                }
            });
        });
    }
});![enter image description here][1]

最佳答案

使用下面这个,它会对你有帮助

$(function () {
  var input = document.createElement("input");
  if (('placeholder' in input) == false) {
    $('[placeholder]').focus(function () {
      var i = $(this);
      if (i.val() == i.attr('placeholder')) {
        i.val('').removeClass('placeholder');
        if (i.hasClass('password')) {
          i.removeClass('password');
          this.type = 'password';
        }
      }
    }).blur(function () {
      var i = $(this);
      if (i.val() == '' || i.val() == i.attr('placeholder')) {
        if (this.type == 'password') {
          i.addClass('password');
          this.type = 'text';
        }
        i.addClass('placeholder').val(i.attr('placeholder'));
      }
    }).blur().parents('form').submit(function () {
      $(this).find('[placeholder]').each(function () {
        var i = $(this);
        if (i.val() == i.attr('placeholder'))
          i.val('');
      })
    });
  }
});

关于javascript - 占位符显示为点状而不是占位符文本(默认文本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25680078/

相关文章:

javascript - 许多人的第一个表格在点击时提交

jquery - 如何使菜单在单击父/子项后保持可见

html - Bootstrap 网格 div 以特定尺寸推出

javascript - 通过 Ajax 的 MYSQL 数据库到 Highcharts 图表

javascript - 为什么在 javascript 中运行代码一次比运行四次慢

javascript - 将数据发布到外部js脚本并提醒他们

html - 在包含溢出元素的容器底部创建白色模糊

html - 带有 HTML 正文的 mailto 链接

javascript - 在React中单击MUI模态组件外部

javascript - 自动完成不起作用,它抛出错误 iElement.autocomplete 不是函数