尝试这样的事情:
<select id="viewSelector"> <option value="0">-- Select a View --</option> <option value="view1">view1</option> <option value="view2">view2</option> <option value="view3">view3</option></select><div id="view1"> <!-- content --> </div><div id="view2a"> <!-- content --> </div><div id="view2b"> <!-- content --> </div><div id="view3"> <!-- content --> </div>
然后在jQuery中:
$(document).ready(function() { $.viewMap = { '0' : $([]), 'view1' : $('#view1'), 'view2' : $('#view2a, #view2b'), 'view3' : $('#view3') }; $('#viewSelector').change(function() { // hide all $.each($.viewMap, function() { this.hide(); }); // show current $.viewMap[$(this).val()].show(); });});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)