问题:如何动态附加ALT或TITLE标记图像?
Code:
<div class="country">
<img src="Flag.png" title="" alt="">
<img src="World.png" title="" alt="">
<img src="Man.png" title="" alt="">
<img src="Woman.png" title="" alt="">
</div>
答案 0 :(得分:0)
$('img').eq(0).attr('alt','Flag').attr('title','Flag')
console.log("alt "+$('img').eq(0).attr('alt'))//setter
console.log("title "+$('img').eq(0).attr('title'))//getter
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="country">
<img src="Flag.png" title="" alt="">
<img src="World.png" title="" alt="">
<img src="Man.png" title="" alt="">
<img src="Woman.png" title="" alt="">
</div>
&#13;
使用.attr()