我正在尝试在移动设备(更具体地说 iPhone Safari)上复制以下 Fiddle ( http://jsfiddle.net/3UWk2/1/ ),但它似乎没有正确运行 javascript,有什么建议吗?谢谢!!
这是js:
<script>
$(document).ready(function() {
$('#00Ni0000007XPVF').bind('change', function() {
var elements = $('div.container_drop').children().hide(); // hide all the elements
var value = $(this).val();
if (value.length) { // if somethings' selected
elements.filter('.' + value).show(); // show the ones we want
}
}).trigger('change');
});
</script>
最佳答案
您似乎正在使用缓存的值。 hide
不返回任何内容。因此,当您尝试再次显示它们时会失败。
var elements = $('div.container_drop').children().hide();
应该是
var elements = $('div.container_drop').children();
elements.hide();
代码
$(document).ready(function() {
$('#00Ni0000007XPVF').bind('change', function() {
// cache the value
var elements = $('div.container_drop').children();
elements.hide(); // hide all the elements
var value = $(this).val();
if (value.length) { // if somethings' selected
elements.filter('.' + value).show(); // show the ones we want
}
}).trigger('change');
});
关于javascript - iPhone 上的动态下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18069170/