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