プロジェクトに Bootstrap を使用しています。プレースホルダーは、Internet Explorer 8 以下を除くすべてのブラウザーで正常に表示されます。
IE8 でプレースホルダー サポートを取得するためのソリューションはありますか?
プロジェクトに Bootstrap を使用しています。プレースホルダーは、Internet Explorer 8 以下を除くすべてのブラウザーで正常に表示されます。
IE8 でプレースホルダー サポートを取得するためのソリューションはありますか?
このプラグインを使用できます https://github.com/mathiasbynens/jquery-placeholder IE6 でも動作します
そのためにjquery透かしプラグインを使用できます
プラグインなしでこれを理解するのは難しくありません。これに近いものがうまくいくと思います。
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');
}
}
});
}
});
}
ルーベンスの回答から追加すると、ここにデモがあります
placeholder
IE9 以下はこの属性をサポートしていません。これを見る
ただし、 EZPZ ヒントを使用してそれを補うことができます。ブラウザが IE の場合は、スクリプトをロードするだけです
<!--[if lt IE 10]>
<script src="PATHTOFILE"></script>
<![endif]-->
placeholder
EZPZ ヒントを使用すると、最新のブラウザーで引き続き使用できます。
例:
<input type="text" id="search" placeholder="Search" />
$("input[type=text]").ezpz_hint();