相关疑难解决方法(0)

输入Internet Explorer的占位符

HTML5 placeholderinput元素上引入了属性,允许显示灰色的默认文本.

可悲的是,包括IE 9在内的Internet Explorer不支持它.

那里已经有一些占位符模拟器脚本了.它们通常通过将默认文本放入输入字段,将其设置为灰色并在您聚焦输入字段后再次将其删除来工作.

这种方法的缺点是占位符文本在输入字段中.从而:

  1. 脚本无法轻松检查输入字段是否为空
  2. 服务器端处理必须检查默认值,以便不将占位符插入数据库.

我想有一个解决方案,其中占位符文本不在输入本身.

html javascript internet-explorer placeholder

173
推荐指数
4
解决办法
24万
查看次数

在IE中显示密码字段的占位符文本

我知道有很多占位符问题,但我想完善我的.

我当前的代码工作得很好并且做了它应该做的事情.问题是,当我去放置"密码"占位符时,它会将占位符放在屏蔽字符中.关于如何解决这个问题的任何想法?

    $(function() {
if(!$.support.placeholder) { 
        var active = document.activeElement;
    $(':text').focus(function () {
        if ($(this).attr('placeholder') != '' && $(this).val() ==  $(this).attr('placeholder')) {
            $(this).val('').removeClass('hasPlaceholder');
        }
    }).blur(function () {
        if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
            $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
        }
    });
    $(':text').blur();
    $(active).focus();
    $('form').submit(function () {
        $(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
    });

    var active = document.activeElement;
    $(':password').focus(function () {
        if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
            $(this).val('').removeClass('hasPlaceholder');
        }
    }).blur(function () {
        if ($(this).attr('placeholder') != '' && ($(this).val() …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery internet-explorer

6
推荐指数
2
解决办法
3万
查看次数

标签 统计

html ×2

internet-explorer ×2

javascript ×2

css ×1

jquery ×1

placeholder ×1