jQuery 占位符未显示在 IE8 for Bootstrap 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13270219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Placeholders are not displaying in IE8 for Bootstrap
提问by user521024
I am using Bootstrap for my project. The placeholders are displaying fine for all browsers except in Internet Explorer 8 and below.
我正在为我的项目使用 Bootstrap。除了 Internet Explorer 8 及更低版本外,占位符在所有浏览器中都可以正常显示。
Are there any solutions to get placeholder support in IE8?
是否有任何解决方案可以在 IE8 中获得占位符支持?
回答by Ruben
you can use this plugin https://github.com/mathiasbynens/jquery-placeholderEven works in IE6
你可以使用这个插件 https://github.com/mathiasbynens/jquery-placeholder甚至可以在 IE6 中使用
回答by rahul
you can use jquery watermark plugin for that
您可以为此使用 jquery 水印插件
回答by Dan
Adding on from Rubens answer there is a demo here
从鲁本斯的回答中添加,这里有一个演示
回答by adeneo
It should'nt be to hard to figure this out without a plugin, I'm guessing something close to this will do the trick:
如果没有插件,应该不难解决这个问题,我猜想接近这个的东西可以解决这个问题:
var test = document.createElement('input');
if (!('placeholder' in test)) {
$('input').each(function () {
if ($(this).attr('placeholder') != "" && this.value == "") {
$(this).val($(this).attr('placeholder'))
.css('color', 'grey')
.on({
focus: function () {
if (this.value == $(this).attr('placeholder')) {
$(this).val("").css('color', '#000');
}
},
blur: function () {
if (this.value == "") {
$(this).val($(this).attr('placeholder'))
.css('color', 'grey');
}
}
});
}
});
}
回答by Eonasdan
IE9 and below doesn't support the placeholder
attribute. See this
IE9 及以下不支持该placeholder
属性。看到这个
You can use EZPZ hintsto supplement it though. Just load the script if the browser is IE
不过,您可以使用EZPZ 提示来补充它。如果浏览器是 IE,只需加载脚本
<!--[if lt IE 10]>
<script src="PATHTOFILE"></script>
<![endif]-->
EZPZ hints allows you to continue to use placeholder
for modern browsers.
EZPZ 提示允许您继续使用placeholder
现代浏览器。
Example:
例子:
<input type="text" id="search" placeholder="Search" />
$("input[type=text]").ezpz_hint();