コメント:この記事では、主にHTML 5入力プレースホルダー属性を紹介して、IEとして完全に機能します。それを必要とする友達はそれを参照できます
jqueryクラスライブラリを参照することを忘れないでください$(document).ready(function(){
if($ .browser.msie)
$( "入力:テキスト、入力:パスワード")。各(function(){
var $ placeholder = $(this).attr( "Placeholder");
var $ width = $(this).css( "width");
var $ id = $(this).attr( "id");
var $ height = parseint($(this).css( "height")) + 6 + "px";
var $ fontsize = $(this).css( "font-size");
var $ fontweight = $(this).css( "font-weight");
var $ lineheight = $ height;
if($(this).css( "line-height")!= "remorm"){
$ lineheight = parseint($(this).css( "line-height")) + 6 + "px";
}
if($ placeholder!= undefined){
$(this)after( "<span class =/" placeholder ph_ " + $ id +"/"style =/" width: " + $ width +"; line-height: " + $ lineheight +"; height: " + $ height +"; font-weight: " + $ fontweight +"; margin-left: - " + $ width +" + $ $プレースホルダー + "</span>");
}
$(this).bind( "keyup"、function(){
if($(this).val()== ""){
$(this).parent()。find( "。ph_" + $ id).css( "display"、 "inline-block");
}
それ以外 {
$(this).parent()。find( "。ph_" + $ id).css( "display"、 "none");
}
});
});
$( "。プレースホルダー")。live( "click"、function(){
$(this).prev()。focus();
});
});
ページコール
<input type = "text" placeholder = "コンテンツが正常である" />を促しています
<入力タイプ= "Text" PlaceHolder = "コンテンツの幅と高さを促しています" />
<input type = "text" placeholder = "私はコンテンツを促しています私は他のスタイルを持っています" />
<input type = "text" placeholder = "他のものを試すことができます" />
スタイル
<style type = "text/css">
.placeHolder {display:inline-block; color:gray; vertical-align:top; overflow:hidden;}
</style>