jqueryを使用してテキストボックスをクリックしたときにヘルパーテキストを表示する
質問
テキストボックスをクリックすると、ヘルパーテキストが表示されます。 例:テキストボックスをクリックした場合、入力する内容を入力してください:ここにユーザー名を入力してください
指定されたコードの下で試しましたが、テキスト "ユーザー名を入力" はフェードアウトしています。フォーカスが別のテキストに変更されるまでテキストを表示したいボックス。
このタイプのコードを提案してください。
<input type = "text"/><span>Enter username</span>
<input type = "text"/><span>Enter password</span>
$(document).ready(function(){
$("input").focus(function () {
$(this).next("span").css('display','inline').fadeOut(1000);
});
});
解決
次のようなことが必要です
$(function(){
$("input")
.focus(function () {
$(this).next("span").fadeIn(1000);
})
.blur(function () {
$(this).next("span").fadeOut(1000);
});
});
他のヒント
fadeIn / fadeOutを使用するだけでなく、CSS表示プロパティを操作している理由がわかりません:
$(document).ready(function(){
$("input").focus(function () {
$(this).next("span").fadeIn(1000);
}).blur(function() {
$(this).next("span").fadeOut(1000);
});
});
所属していません StackOverflow