如题,我想判断a是否是undefined,下面的代码却无效,请问哪里出错了?
$(document).ready(function(){
$('img').each(function() { var a = $(this).attr("alt");
if (a != undefined) {
$(this).before('') ;});
} else {
$(this).before('<span class="caption">' + a + "</span>") ;});
}
});
图像的alt属性在没有显式赋值的情况下则该属性为null,不是undifined