我在asp中有很多图像
<img src="site.com/img" class="post-image" alt="a long description"/>
<img src="site.com/img_1" class="post-image" alt="a long description2"/>
Run Code Online (Sandbox Code Playgroud)
图片标签中没有标题.我需要使用alt文本来设置每个图像的标题.我正在使用jquery来实现这一目标
<script type="text/javascript">
$('img').attr('title',$(this).attr('alt'));
</script>
Run Code Online (Sandbox Code Playgroud)
它不起作用,我错过了什么.请帮忙.
this在你的代码中没有引用img元素.您需要使用以回调作为参数的.attr() setter
jQuery(function(){
$('img').attr('title', function(){
return $(this).attr('alt')
});
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
979 次 |
| 最近记录: |