admin管理员组文章数量:1356881
When using Internet Explorer 10 and 11, input placeholder text is removed if the input is focused using the autofocus
attribute. For example:
<input type="textbox" value="" placeholder="Example text" autofocus>
Demo: /
How can I ensure the placeholder text isn't removed?
Ref:
When using Internet Explorer 10 and 11, input placeholder text is removed if the input is focused using the autofocus
attribute. For example:
<input type="textbox" value="" placeholder="Example text" autofocus>
Demo: https://jsfiddle/ompkwtz5/
How can I ensure the placeholder text isn't removed?
Ref: https://connect.microsoft./IE/feedback/details/885747/ie-11-fires-the-input-event-when-a-input-field-with-placeholder-is-focused
Share Improve this question asked May 6, 2015 at 2:38 henrywrighthenrywright 10.3k25 gold badges97 silver badges153 bronze badges 3- Also IE9, see stackoverflow./questions/5522164/… – Kevin Hakanson Commented May 6, 2015 at 2:58
- @KevinHakanson I think IE9 is slightly different. It doesn't support placeholders at all whereas 10 and 11 support them. 10 and 11 just handle them in a crazy way (they're removed when the input is focused). – henrywright Commented May 6, 2015 at 3:28
- you are correct, that answer linked to polyfills that work in both IE9, 10 and 11 to get expected behavior – Kevin Hakanson Commented May 6, 2015 at 19:54
2 Answers
Reset to default 2Found a solution only with css. https://jsfiddle/nikdko/grc6v03a/
PS:withs input:valid + .fakePlaceholder {display:none } ie gets freeze
<input type="text" pattern=".+" required="" />
<span class = "fakePlaceholder">Fake placeholder />
input {
position: relative;
top: 0;
border: 1px solid #999;
z-index: 1;
}
.fakePlaceholder{
color: #7D838A;
position: absolute;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
width: 100%;
pointer-events: none;
left: 0;
z-index: 1;
padding-left: 10px;
}
input:valid {
background-color: #FFFFFF;
z-index: 2;
}
It's an IE bug, the one in your reference link.
Take a look at jquery-placeholder. Will also support IE6! I'm not sure if it will work out of the box though, because IE10 is supposed to support the placeholder
attribute, so check if jQuery.fn.placeholder.input
is true
(more info in the README). If it is, the plugin won't do anything, so you might need to override its checking behaviour.
Amazing that the bug is still active.
版权声明:本文标题:javascript - Internet Explorer 10 and 11 remove placeholder text when the input is focused - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743949687a2567059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论