jQuery为没有alt标记的图像提供边框
如何在没有alt标签的情况下给图片加边框,我试过了,但是我很绿,所以可能完全是废话jQuery为没有alt标记的图像提供边框,jquery,html,css,Jquery,Html,Css,如何在没有alt标签的情况下给图片加边框,我试过了,但是我很绿,所以可能完全是废话 $( ':image:not([alt])' ).css('border', '5px solid red'); jQuery中没有:image选择器,您需要使用: $('img:not([alt])').css('border', '5px solid red'); 你就快到了 首先,使用:image是不正确的。你必须使用 $("image") 选择图像 另一种选择是使用 [type="image"]
$( ':image:not([alt])' ).css('border', '5px solid red');
jQuery中没有
:image
选择器,您需要使用:
$('img:not([alt])').css('border', '5px solid red');
你就快到了
首先,使用:image是不正确的。你必须使用
$("image")
选择图像
另一种选择是使用
[type="image"]
为了可读性。您可以在此处阅读更多内容:
然后使用
:not()
允许您指定选择器。也可以使用.not(),并使用逗号或空格分隔选择器。参考:
因此,要选择页面上没有alt属性的所有图像,请执行以下操作:
$("image:not(alt)").css('border', '5px solid red');
希望这有帮助。$('img:not([alt])).css('border','5px solid red')代码>这是一把小提琴: