2011-01-15 25 views
0
<div class="field"> 
    <input name="password" type="password" /> 
</div> 

入力にフォーカスがあるときに背景画像のフィールドdivの位置を変更したいと思います。 jqueryでそれを行うための任意のアイデア?ありがとう。入力時に背景の位置を変更する方法

私はこれを試していませんでしたが、私は次のように動作するはずだと思う

答えて

0

$('input:password').focus(
    function(){ 
     $(this).parent().css({'background-position': 'Xpx Ypx'}); 
    }).blur(
    function(){ 
     $(this).parent().css({'background-position': 'Xpx Ypx'}); 
    }); 
0

あなたのパスワード入力にfocusイベントを監視して、jQueryのcss()を使用してターゲットにbackground-position CSSプロパティを変更することができます方法。

$('div.field input[name="password"]').focus(function() { 
    $(this).closest('div.field').css('background-position', '10px 10px'); 
}); 
0
$('.field input').focus(function() { 
    $(this).addClass('focus') 
}); 

それからちょうど.field.focusクラスの背景の位置を設定します。

+0

このソリューションはすべての入力フィールドで機能し、プレゼンテーションマークアップを機能的なjQueryとは別に保つことができます。 – S16

関連する問題