我爲我的項目使用Bootstrap。佔位符在所有瀏覽器中都可以正常顯示,除了Internet Explorer 8和以下版本。在IE8中不顯示佔位符Bootstrap
是否有任何解決方案在IE8中獲得佔位符支持?
我爲我的項目使用Bootstrap。佔位符在所有瀏覽器中都可以正常顯示,除了Internet Explorer 8和以下版本。在IE8中不顯示佔位符Bootstrap
是否有任何解決方案在IE8中獲得佔位符支持?
你可以使用jQuery插件水印爲
IE9和下面不支持placeholder
屬性。請參閱this
您可以使用EZPZ hints來補充它。如果瀏覽器是IE
<!--[if lt IE 10]>
<script src="PATHTOFILE"></script>
<![endif]-->
EZPZ提示,您可以繼續使用placeholder
現代瀏覽器只需加載腳本。
例子:
<input type="text" id="search" placeholder="Search" />
$("input[type=text]").ezpz_hint();
它should'nt是很難弄清楚這一點無需插件,我猜一些接近這將這樣的伎倆:
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');
}
}
});
}
});
}
IE崩潰的'如果(!'placeholder'in test){' –
@pinouchon - 它不適合我,但是如果這是一個問題,你需要做的就是將它包裝在括號內,並且應該解決它。補充說,以及答案。 – adeneo
可以使用這個插件 https://github.com/mathiasbynens/jquery-placeholder 即使工作在IE6
添加從魯本斯回答這裏有一個演示
在IE中不支持佔位符,您必須使用一個值並將其設置爲焦點/模糊等與JavaScript。 – adeneo
您可以使用['placeholder'屬性填充](https://github.com/jamesallardice/Placeholders.js)爲所有瀏覽器中的'placeholder'屬性添加支持。 IE不支持它低於版本10. –
你應該接受一個答案,如果他們幫助你 – Eonasdan