我正在寻找一种方法来动态查看 img 是否有一个包含用户输入的字符串的 alt 标签一切正常,但我想让它不区分大小写以提高可用性
我的PHP
<div class="box">
<div class="box-heading"><span><?php echo $heading_title; ?></span> <input type="text" id="refine" placeholder="refine"></div>
<div class="box-content">
<div class="box-category">
<ul class="manufacturers">
<?php foreach ($manufacturers as $manufacturer) { ?>
<li class="manufacturer" >
<a href="<?php echo $manufacturer['href']; ?>">
<img src="<?php echo $manufacturer['image']; ?>" alt="<?php echo $manufacturer['name']; ?>" />
</a>
</li>
<?php } ?>
</ul>
</div>
和jQuery
<script>
$("#refine").keyup(function() {
var filter = $(this).val().toLowerCase();
if(filter) {
$matches = $('.manufacturer a img[alt*=' + filter + '] ');
console.log($matches);
$('.manufacturer a img').not($matches).slideUp();
$matches.slideDown();
} else {
$('.manufacturer a img').slideDown();
}
return false;
});
</script>
我想在标记中保留制造商名称的大写。