我已经尝试了这里论坛上列出的几件事,但我无法让这个工作。
所以我的问题是:如何检查数组是否为空,如果是则隐藏元素?
也许我做错了什么?
我的代码:
var listaSelection = {
"category": [{ value: "1234", text: "Test" }]};
$("select#list").change(function(){
$("#cat3").html($("#list option:selected").text());
var options = '';
listsa = listaSelection[$(this).val()];
$('select#listA').empty();
options += '<option value="">Choose</option>';
$.each(listsa, function() {
options += '<option value="' + this.value + '">' + this.text + '</option>';
});
if(listsa.length > 0){
$('select#listA').append(options);
$('.zoeken-select.listA').fadeIn(300);
}else{
//this array is empty
return false;
}
});
的HTML
<div class="zoeken-select course">
<div class="zoeken-value" id="cat2">Selecteer je sector/locatie</div>
<div class="zoeken-handle"></div>
<select id="course" class="gui-validate">
</select>
</div>
<div class="zoeken-select list">
<div class="zoeken-value" id="cat3"></div>
<div class="zoeken-handle"></div>
<select id="list" class="gui-validate">
</select>
</div>
<div class="zoeken-select listA">
<div class="zoeken-value" id="cat4"></div>
<div class="zoeken-handle"></div>
<select id="listA" class="gui-validate">
</select>
</div>