2个回答

8
你差点就成功了!!!
$('a[href]').filter(function() {
  return /(jpg|gif|png)$/.test($(this).attr('href'))
}).bind('mouseover', function(){
  alert('foo');
})

1

您可能希望使用不区分大小写的正则表达式检查文件名。因为有些文件可能是“.JPEG”而不是“.jpeg”。因此,请尝试以下内容:

var file = "life/is/short.JPG"

if (/(jpg|jpeg|gif|png)$/i.test(file)) {
    alert("the file is an image");
}
else {
    alert("the file is not an image");
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接