0
私はこれらの3つすべてを試しましたが、入力後にspan
にテキストを追加できませんでした。私が間違っていることを教えてもらえますか? Div After Inputの選択に関する問題
私はこれらの3つすべてを試しましたが、入力後にspan
にテキストを追加できませんでした。私が間違っていることを教えてもらえますか? Div After Inputの選択に関する問題
$(this).next()
$("input").on("keydown", function(){
$(this).next('.error').html('Becareful Baby!');
$(this).closest('br').next('.error').html('Becareful Baby!');
$(this).closest('.error').html('Becareful Baby!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="fname" id="fname" class="nametxt" />
<br />
<span class="error"></span>
$(this).next('.error').html('Becareful Baby!');
$(this).closest('br').next('.error').html('Becareful Baby!');
$(this).closest('.error').html('Becareful Baby!');
はあなたが選択した1後の要素を取得します。セレクタを指定すると結果がさらに絞り込まれます。あなたの入力要素の後の要素は
<br/>
なので、それは
.next()
があなたに与えるものです。
$(this).siblings('.error')
をお勧めします。ここに例があります:https://jsfiddle.net/77nvepos/1/
こんにちはジェイクですが、これはすべての可能な既存の '.error' –