Typecho的文章里图片都没有链接到自身。有时想看大图就必须复制图片URL到浏览器打开很不方便有没有。
1、使用Jquery实现
首先在header.php模板引用Jquery。然后在文章模板post.php里最尾部增加如下代码:
代码: 全选
<script type="text/javascript">
$(document).ready(function(){
$('.img').wrap(function () {
return '<a href="' + this.src + '" title="' + this.alt + '"></a>';
})
});
</script>
2、直接使用Javascript实现
直接在post.php模板尾部添加下面的代码。
代码: 全选
<script type="text/javascript">
var Img = document.getElementById("article_content").getElementsByTagName("img");
for (var i = 0; i < Img.length; i++) {
Img[i].onclick = function () {
window.open(this.src);
}
}
</script>
原文出处:http://www.chenghuajie.cn/204.html