如何将条件添加到空白 select2 选项? :include_blank => 是吗?

how to add conditional to blank select2 option? :include_blank => true?

当select选项为空白占位符时,如何找到这个,从而执行相应的jquery / javascript?

这是我的标记 (haml):

= form_tag(compare_path, method: 'get', remote: true, id: 'compare_form') do
          = select_tag "votus_friend_id", options_from_collection_for_select(@votus_friends, :id, :full_name, @comparison.votus_friend.id), :include_blank => true, :class => "compare-search", :style => "width:100%; margin-left: 3px;"

这是我的 JS。我知道它离这里很远。我似乎无法找到从 select2 返回的空白占位符的确切值,以便 运行 条件:

$('.compare-search').on('change', function() {

  console.log('thisss', $('<select/>')  );

  if ($('.compare-search').val() === '') {
    $('.vScoreExplain').show();
    $('.stats').hide();
  }
  else {
    $('.vScoreExplain').hide();
    $('.stats').show();
  }
});

你可以试试这个:

$('.compare-search').on('change', function() {

  if ($(this).val().length) {
    $('.vScoreExplain').hide();
    $('.stats').show();
  }
  else {
    $('.vScoreExplain').show();
    $('.stats').hide();
  }
});