Komentar: Artikel ini terutama memperkenalkan atribut placeholder input HTML 5 untuk melayani dengan sempurna sebagai IE. Teman yang membutuhkannya bisa merujuknya
Ingatlah untuk merujuk perpustakaan kelas jQuery$ (dokumen) .ready (function () {
if ($ .browser.msie)
$ ("Input: Teks, Input: Kata Sandi"). Setiap (fungsi () {
var $ placeholder = $ (ini) .attr ("placeholder");
var $ width = $ (this) .css ("width");
var $ id = $ (ini) .attr ("id");
var $ height = parseInt ($ (this) .css ("height")) + 6 + "px";
var $ fontSize = $ (this) .css ("font-size");
var $ font weight = $ (this) .css ("font-weight");
var $ lineHeight = $ tinggi;
if ($ (this) .css ("line-height")! = "normal") {
$ lineHeight = parseInt ($ (this) .css ("line-height")) + 6 + "px";
}
if ($ placeholder! = tidak terdefinisi) {
$ (ini). Setelah ("<span class =/" placeholder ph_ " + $ id +"/"style =/" width: " + $ width +"; line-height: " + $ lineHeight +"; tinggi: " + $ tinggi +"; "font-weight:" + $ font + "; margin-left:" + $ ">" font-weight: " + $ fontweight +"; margin-left: " + $ width +" font + ";" $ placeholder + "</span>");
}
$ (this) .bind ("keyup", function () {
if ($ (this) .val () == "") {
$ (ini) .parent (). find (". ph_" + $ id) .css ("display", "inline-block");
}
kalau tidak {
$ (ini) .parent (). find (". ph_" + $ id) .css ("display", "none");
}
});
});
$ (". Placeholder"). Live ("Click", function () {
$ (ini) .prev (). focus ();
});
});
Panggilan halaman
<input type = "text" placeholder = "Saya meminta kontennya normal" />
<input type = "text" placeholder = "Saya meminta lebar dan tinggi konten" />
<input type = "text" placeholder = "Saya meminta konten saya memiliki gaya lain" />
<input type = "text" placeholder = "Anda dapat mencoba yang lain" />
gaya
<type style = "text/css">
.placeHolder {display: inline-block; warna: abu-abu; vertikal-align: atas; overflow: tersembunyi;}
</tyle>