2012-03-02 6 views
0

ここでは、フォーム上の任意の場所(ポップアップ内にある)をクリックすると "text2display"に焦点を当てるコードです。しかし、どのように「タブ」であれば、他の場所(例えば、ブラウザのURL)をナビゲートし、それを検出し、「text2display "」に戻って焦点を当てて返す方法をバーコードリーダの入力を検出する

$("#barcode_form").click(function(){ 
    var focusedElement = ""; 
    $(":focus").each(function(){ 
    focusedElement = $(this).attr("id")     
    }); 
    if(focusedElement == ""){ 
    $('#text2display').focus() 
    } 
}) 
+0

これはどのブラウザで実行されますか?モバイルデバイスかデスクトップですか? –

答えて

0

あなたは(.blurを望むことでしょう);?機能。要素は、「フォーカス」を持ち、ユーザが「集中」の項目を残し、「ぼかし」は呼び出され、バック要素にイベントを送信するたびに。フォローする例を。

if(focusedElement == ""){ 
    //if our focused element is empty 
    $('#text2display').live('blur', function(){ 
    //when the target loses focus, we invoke blur, the next line focuses again. 
    //it's also a best practice to do something like fading in the border, 
    $("#text2display").focus(); 
    }); 
} 

また、私が提案する可能性がある場合その要素にフォーカスが戻ってきたことをユーザーに知らせることをお勧めします。これを行う最も良い方法は、「赤い」枠を追加し、その枠線をフェードアウトすることです。 - >

また
if(focusedElement == ""){ 
    //if our focused element is empty 
    $('#text2display').live('blur', function(){ 
    //when the target loses focus, we invoke blur, the next line focuses again. 
    //it's also a best practice to do something like fading in the border, 
    $("#text2display").focus(function(){ 
     $(this).animate({ 
     //when the element has been re-focused, we'll give it a red border briefly. 
     borderColor: '#ff0000'; 
     }, function(){ 
      //once the animation completes, fade the border out      
      $(this).animate({ borderColor: 'transparent' }, 2000); 
     } 
    ); 
    }); 
    }); 
} 

、我々は問題のサイズを変更したくないので、私たちは、これがあなたのためにうまく動作するはずです私たちの入力に

input{ 
    border:1px solid transparent; 
} 

をいくつかのCSSを追加する必要があります。

+0

お返事ありがとうございますOhgodwhy、しかし働いていないようです。また、私は "$("#barcode_form ")の置き換えを探しています。ポップアップが表示されているときにバーコードからの入力を検出したいので、click(function()"をクリックしてください。 –

+0

btw: –

+0

$ "#barcode_form")((関数)をクリック {VARのfocusedElement = ""; $( "焦点")各(関数(){ focusedElement = $(この).ATTR( "ID" ) }); IF(focusedElement == ""){ $( '#1 text2display')は、( 'ぼかし' をライブ機能() { $( "#text2display")。focus() }); } } –

関連する問題