【问题标题】:how to add conditional to blank select2 option? :include_blank => true?如何将条件添加到空白 select2 选项? :include_blank => 真的吗?
【发布时间】:2015-05-24 17:23:34
【问题描述】:

当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();
  }
});

【问题讨论】:

    标签: jquery ruby-on-rails jquery-select2 ui-select2 select2-rails


    【解决方案1】:

    你可以试试这个:

    $('.compare-search').on('change', function() {
    
      if ($(this).val().length) {
        $('.vScoreExplain').hide();
        $('.stats').show();
      }
      else {
        $('.vScoreExplain').show();
        $('.stats').hide();
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 2013-06-11
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      相关资源
      最近更新 更多