【发布时间】:2014-05-29 04:49:59
【问题描述】:
我正在尝试根据下拉菜单 #map-type、#map-date、#map-county 的选择来显示/隐藏动态生成的 div (.map-thumb),但我无法使其正常工作。有什么想法吗?
HAML
.row#map-thumbnail-wrapper
.medium-4.columns
%select#map-type
%option.filter Type of Program
- MapChoices['program'].each do |program|
%option.filter{value: program.downcase.gsub(' ', '-')}= link_to program, '#'
.medium-4.columns
%select#map-date
%option.filter Date Constructed
- [*2007..Date.today.year].each do |year|
%option.filter{value: year}= year
.medium-4.columns
%select#map-county
%option.filter County
- current_locations = @cms_page.children.published.map { |i| cms_page_content(:county, i).capitalize }.keep_if(&:present?).uniq.sort
- current_locations.each do |county|
%option.filter{value: county.downcase.gsub(' ', '-')}= link_to county, '#'
.well-thumbnails
- @cms_page.children.published.in_groups_of(6, false) do |location_row|
.row
- location_row.each do |location|
.medium-2.columns
- date_created = cms_page_content(:date_created, location)
.map-thumb.all{class: "#{cms_page_content(:program, location).downcase.gsub(' ', '-')} #{DateTime.parse(date_created).strftime('%Y') if date_created.present?} #{cms_page_content(:county, location).downcase}"}
- preview_image = cms_page_content('preview.image', location)
= link_to image_tag(preview_image.file.url(:original)), location.full_path if preview_image
.map-yellow
.map-align-mid
.thumb-text-wrapper
= cms_page_content(:name, location)
jQuery
$(function(){
$select = $('#map-date'),
$select2 = $('#map-type'),
$select3 = $('#map-county');
var selectAry = [$select, $select2, $select3];
$.each(selectAry, function(index, value){
value.change(function() {
var filters = $(this).val();
$('div').hide();
$('div[class$="' + filters + '"]').show();
});
});
});
编辑
【问题讨论】:
-
你能发布一个指向 HTML 的链接吗?然后人们可以将其发布到 fiddle.js
-
在上面的编辑中添加。