// 获取所有的 img 标签 var imgTags = document.querySelectorAll('img'); $(function(){ // 循环遍历每个 img 标签 imgTags.forEach(function(img) { // 获取当前 img 标签的 alt 属性值 var alt = img.getAttribute('alt'); // 检查 alt 属性是否为空 if (!alt) { // 如果是空的话,设置为指定文本 img.setAttribute('alt', '3499拉斯维加斯科技'); } }); });