2

ボックスにカーソルがあるかどうかを確認する方法がわかりません。テキスト ボックスが空またはアクティブでない場合、div を置き換えたい。

.js.erb ファイル

if($('#headersearch').val().trim() ==  "") {
  $("#header_user_list").html('');}
else if(!$('#headersearch').is(":focus")){          <-- this line isnt working
  $("#header_user_list").html('');}
else{$("#header_user_list").html('<%= j render @header_users %>')}
4

2 に答える 2

3

focusout-documentation hereを使用できます。

于 2013-07-09T08:40:57.907 に答える
1

ここで私はいくつかの行をコーディングしました。これがあなたが探しているものかもしれません

$('#headersearch').focusout(function(){
$("#header_user_list").html('focusout');
});          


$('#headersearch').focusin(function(){
 $("#header_user_list").html('focusin');
})

フィドル

于 2013-07-09T08:45:57.987 に答える