<input type="text" name="email" class="w_def_text" title="Email*" /> "> <input type="text" name="email" class="w_def_text" title="Email*" /> "> <input type="text" name="email" class="w_def_text" title="Email*" /> " />
入力の title 属性を "field_title" クラスにまたがるように変換するjqueryを作成しました。私は入力をクリックしたときにspan class hideを押しても入力フィールドは無効のままです。問題は、入力フィールドを有効にできないことです。
title
"field_title"
<div class="field"> <input type="text" name="email" class="w_def_text" title="Email*" /> </div> <script> function init_fields() { $('.w_def_text').each(function() { var text = $(this).attr('title'); var html = '' + text + ''; $(this).parent().append(html); if($(this).val() == '') { $(this).hide(); $(this).next().show(); } else { $(this).css({'display' : 'block'}); $(this).next().hide(); } }); $('.w_def_text').live('blur', function() { if($(this).val() == '') { $(this).hide(); $(this).next().show(); } }); $('.w_def_text ~ span').live('click', function() { $(this).hide(); $(this).prev().css({'display' : 'block'}).focus(); }); } </script>
$('.w_def_text ~ span').live('click', function() { $(this).hide(); $(this).prev().prev().css({ 'display': 'block' }).focus(); });
これが入力であるため、 .prev()。prev()が必要です。そして、第二の機能
.prev()。prev()
$('.w_def_text').live('blur', function() { if($(this).val() == '') { $(this).hide(); $(this).next().next().show(); } });
.next()。next()などが必要です。今何が間違っているのか理解しておくべきです。 :)
.next()。next()
input
プレースホルダ
私は代わりに考える:
$(this).parent().append(html);
あなたはしたい:
$(this).after(html);
また、 .next()。show()の代わりに、より明示的に指定することもできます。ターゲットにする兄弟クラスを指定します。
.next()。show()
$(this).next('.error').show() ... $(this).next('.error').hide()
$(this).next( '。error')と $(this) .hide()はあなたが望む結果を得るでしょうか?
$(this) .hide()