Kommentar: In diesem Artikel wird hauptsächlich das HTML 5 -Eingabe -Platzhalterattribut vorgestellt, um perfekt als dh zu dienen. Freunde, die es brauchen, können sich darauf beziehen
Denken Sie daran, auf die JQuery -Klassenbibliothek zu verweisen$ (Dokument) .Ready (function () {
if ($ .browser.msie)
$ ("Eingabe: Text, Eingabe: Passwort"). Jede (function () {
var $ placeholder = $ (this) .attr ("Platzhalter");
var $ width = $ (this) .css ("width");
var $ id = $ (this) .attr ("id");
var $ height = parseInt ($ (this) .css ("Höhe")) + 6 + "px";
var $ fontSize = $ (this) .css ("Schriftgröße");
var $ fontWeight = $ (this) .css ("Schriftgewicht");
var $ lineHeight = $ Höhe;
if ($ (this) .css ("Linienhöhe")! = "normal") {
$ lineHeight = parseInt ($ (this) .css ("Linienhöhe") + 6 + "px";
}
if ($ platzhalter! = undefiniert) {
$ (this) .After ("<span class =/" Platzhalter ph_ " + $ id +"/"style =/" width: " + $ width +"; Zeilenhöhe: " + $ lineHeight +"; + "</span>");
}
$ (this) .bind ("keyUp", function () {
if ($ (this) .val () == "") {
$ (this) .Parent (). Find (". Ph_" + $ id) .css ("Anzeige", "Inline-Block");
}
anders {
$ (this) .Parent (). find (". Ph_" + $ id) .css ("display", "keine");
}
});
});
$ (". Platzhalter"). Live ("Click", function () {
$ (this) .prev (). Focus ();
});
});
Seitenanruf
<Eingabe type = "text" placeholder = "Ich fordere den Inhalt auf" />
<Eingabe type = "text" placeholder = "Ich fordere die Breite und Höhe des Inhalts auf" />
<Eingabe type = "text" placeholder = "Ich fordere Inhalte auf. Ich habe andere Stile" />
<Eingabe type = "text" placeholder = "Sie können andere versuchen" />
Stil
<style type = "text/css">
Placeholder {Display: Inline-Block; Farbe: Grau; vertikaler Align: Top; Überlauf: versteckt;}
</style>