入力フィールドのフォーカスのある要素の親にクラスを追加しようとしています。入力フィールドに焦点が当てられていますが、フィールドが追加されているので、フォーカスを.parent()を使用して全体に丸める必要があります。私は以下にいくつかのことを試しましたが、うまく動作しません。ここで親にクラスを適用しようとしています
はHTMLである:ここでは
<div class="input-group">
<span class="input-group-addon">£</span>
<input type="text" class="form-control mort-calc-field comma" id="pp">
</div>
はjQueryのです:代わりにあなたがfocusin
を使用する必要がonfocus
の
$(document).ready(function(){
$('.mort-calc-field').onfocus(function(){
$(this).parent().addClass('calc-box-shadow');
});
$('.mort-calc-field').focusout(function(){
$(this).parent().removeClass('calc-box-shadow');
});
});
ありがとう、私は他の答えを使用しましたが、これも同様に機能しました。 – Michael