如何更改它(http://jsfiddle.net/jRAAg/2/),以便根据我从下拉列表中选择的组合,它会在上面显示不同的值。例如,如果我只选择“男性”和“18-24”,它应该只显示与该选择相对应的分数。提前致谢!
代码:
<div id="segmentscore" data-gender="1" data-age="0">100</div>
<div id="segmentaware" data-gender="1" data-age="0">150</div>
<div id="segmentscore" data-gender="1" data-age="2">190</div>
<div id="segmentaware" data-gender="1" data-age="2">100</div>
<div id="select1">
<select id="genderlist">
<option value="0"></option>
<option value="1">Male</option>
<option value="2">Female</option>
</select></div>
<div id="select2"><select id="agelist">
<option value="0"></option>
<option value="1">12-17</option>
<option value="2">18-24</option>
<option value="3">25-34</option>
<option value="4">35-44</option>
<option value="5">45-54</option>
<option value="6">55-99+</option>
</select></div>
jQuery
$('#genderlist').on('change', function() {
$('[data-gender]').each( function(index, element) {
element.style.display = 'none'
})
gender = $('#genderlist')[0].value
$('[data-gender='+gender+']').each( function(index, element) {
element.style.display = 'block'
})
})
$('#agelist').on('change', function() {
$('[data-age]').each( function(index, element) {
element.style.display = 'none'
})
age = $('#agelist')[0].value
$('[data-age='+age+']').each( function(index, element) {
element.style.display = 'block'
})
})