我正在使用jQuery,我需要过滤一些数据。在每个浏览器上,我的代码都能按预期工作。但是,在移动设备上,它会隐藏所有内容,并且无法正常工作。
我做错了什么?谢谢您的帮助:)
<form id="region-filter" method="post">
<label>
<span>Nach Region suchen:</span>
<input type="text">
</label>
</form>
<div class="gridWrapper">
<?php
$regions = rest_api_call('regions.json');
?>
<?php foreach($regions['message']['data'] as $region) : ?>
<?php //var_dump($region); ?>
<div class="grid grid-ms-1-2 grid-md-1-3 grid-xl-1-4">
<div class="region" data-id="<?php echo $region['id']; ?>">
<div class="check"></div>
<div class="city-wrapper" style="background-image: url('<?php echo $region['icon']['svg']; ?>');">
<div class="city-name">
<?php echo $region['name']; ?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
$('#region-filter input').on({
input: function() {
let val = $(this).val();
$('.regions .gridWrapper .grid').each(function() {
let name = $(this).find('.city-name').text();
let match = name.toLowerCase().indexOf(val);
if (match !== -1) {
$(this).show();
} else {
$(this).hide();
}
});
},
keypress: function(e) {
let keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
}
});