$('a[href]').filter(function() {
return /(jpg|gif|png)$/.test($(this).attr('href'))
}).bind('mouseover', function(){
alert('foo');
})
您可能希望使用不区分大小写的正则表达式检查文件名。因为有些文件可能是“.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");
}