2016-07-20 4 views
0

ユーザが入力をクリックしたりタブから外したりするときにdivをクリアしようとしていますが、ユーザが別のウィンドウやブラウザタブ。JQuery divをクリアして入力をクリックしたときにオフにしないページ

$input.on('blur focus mousedown', function() { 
    $input.val(""); 
    $("#cors-test-invalid").html(""); 
    $("#cors-test-views").html(""); 
    $("#cors-test-workbooks").html(""); 
    $("#cors-test-datasources").html(""); 
    $("#cors-test-projects").html(""); 
    $("#cors-test-users").html(""); 
}); 
+1

ようにそれを行うことができます: '私はこれまでのところ、両方のケースではdiv要素をクリアしている何

$( "div [id^= 'cors-test']").html( ""); ' – empiric

答えて

1

あなたが開始-とセレクタとのdiv部分を短くすることができ、この

$(document.body).on('click',function(){ 
//here its a click on body which eliminates the other tabs or windows 
if(!$input.is(":focus")) 
{ 
//here element doesnt have focus, so we are good to do the logic 
    $input.val(""); 
    $("#cors-test-invalid").html(""); 
    $("#cors-test-views").html(""); 
    $("#cors-test-workbooks").html(""); 
    $("#cors-test-datasources").html(""); 
    $("#cors-test-projects").html(""); 
    $("#cors-test-users").html(""); 

} 

}); 
+0

このソリューションは素晴らしいです。これはニッチ・ピカイですが、これを行う方法がわかっているとすばらしいことになります。ボディだけでなくページ全体にアクションを起こす方法はありますか?サイトのボディは全幅に渡っていません(設計決定) – anton2g

+1

ドキュメントはやると思いますが、まずそれを試してみてください。 @ anton2g – MoustafaS

+0

完璧です。ありがとう – anton2g

関連する問題