占位符在 IE10 中不起作用

2023-12-02

html:

<div class="div-input">
    <input type="text" id="loginname" name="username" value="" maxlength="25" 
        class="form-input" placeholder="Username"
    />
</div>
<div class="div-input">
    <input type="password" id="loginpassword" name="password" maxlength="25" 
        class="form-input" placeholder="Password"
    />
</div>
<div>
    <input type="submit" name="login" value="LOGIN" class="form-button" 
        onclick="return check_login(&quot;/&quot;)" 
    />
    <span id="logInfo"></span><span style="display: none;" id="overlay"></span>
    <span style="display: none;" id="popup">
        <img src="/public/images/loading.gif" />
    </span>
</div>

我的问题是,占位符在所有浏览器中都工作正常,对于 IE8 和 IE9,我使用 Javascript 来解决它,但在 IE10 中,占位符可以工作,但不是以正确的方式。

  1. 发生的情况是在页面加载时,如果Placeholder是占位符,我只得到Placeholde作为 IE10 中的占位符(最后一个字母消失),但是如果我在输入框内单击并在页面外部,它会显示正确的占位符:Placeholder.

  2. 如果我在输入字段中输入任何单词,我会在输入字段的角落处看到一个十字符号(闭合符号),这种情况仅在 IE10 中发生。


听起来您的 javascript 正在破坏本机 IE10 占位符功能。

要测试这个问题并希望修复它,请将您为占位符编写的 javascript 包装在条件语句中,以便它仅适用于 IE9 及更低版本。

<!--[if lt IE 9]>
<script>
  document.createElement('header');
  document.createElement('nav');
</script>
<![endif]-->

或者,Mathias Bynens 有一个非常好的 jquery 插件,可以免费使用并为您处理所有这些:https://github.com/mathiasbynens/jquery-placeholder

一些 CMS 已经有一个使用此代码构建的插件。 WordPress 插件在这里:http://wordpress.org/plugins/html5-placeholder-polyfill/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

占位符在 IE10 中不起作用 的相关文章

随机推荐