绿色应用市场
当前位置:首页 > 教程笔记 > 正文

Z-Blog 评论留言的引用按钮写法详解

发布时间:2022-08-02 17:10:59来源:周小白软件园编辑:本站整理

Z-Blog 博客的评论留言引用按钮的写法在 Z-Blog 官方的Wiki里也有说明,云初冀北制作 Z-Blog 主题对评论留言的引用按钮进行编写的时候去看过官方的讲解,感觉 Z-Blog 官方Wiki给出的相关说明太过于简单,对新手的话可能会造理解上的一些错误,我之前就有这类似经历,导致我花了过多的时候在引用按钮的写法上面。

Z-Blog 评论留言的引用按钮写法详解

Z-Blog 引用所用的JS函数:

引用的函数: InsertQuote(参数1[评论者],参数2[评论内容])this.parentNode 表示该节点的上一节点getElementsByTagName(‘a’)[2].innerHTML 表示获取第二个元素的内容,即<#article>同上,getElementsByTagName(‘li’)[2].innerHTML 为<#article>

注:其中getElementsByTagName(‘a’)[2]中的a和2是要按实际变化的;getElementsByTagName(‘li’)[2]也一样。

Z-Blog 默认主题的模板b_article_comment.html代码结构如下:

<ul class="msg">    <li class="msgname"><span class="comment-quote-icon"><a onclick="InsertQuote(this.parentNode.parentNode.parentNode.getElementsByTagName('a')[2].innerHTML,this.parentNode.parentNode.parentNode.getElementsByTagName('li')[2].innerHTML);return false;" href=""><img src="<#ZC_BLOG_HOST#>image/common/quote.gif" height="9" width="9" alt="quote" title="quote" /></a></span>&nbsp;<a name="cmt<#article/comment/id#>"><#article/comment/count#></a>.<a><#article/comment/name#></a></li>    <li class="msgurl"><a href="<#article/comment/urlencoder#>" rel="nofollow" target="_blank"><#article/comment/url#></a></li>    <li class="msgarticle"><#article/comment/content#></li>    <li class="msgtime"><#article/comment/posttime#>&nbsp;<a href="#comment" onclick="RevertComment('<#article/comment/id#>')"><#ZC_MSG265#></a></li></ul>

其引用按钮写法如下:

<a onclick="InsertQuote(this.parentNode.parentNode.parentNode.getElementsByTagName('a')[2].innerHTML,this.parentNode.parentNode.parentNode.getElementsByTagName('li')[2].innerHTML);return false;" href=""><img src="<#ZC_BLOG_HOST#>image/common/quote.gif" height="9" width="9" alt="quote" title="quote" /></a></span>

更改代码结构的写法示例:

如果b_article_comment.html代码结构如下:

<div class="msg"><cite>评论者</cite><blockquote>评论内容</blockquote><p>网站</p><p>时间</p></div>

添加评论引用按钮后的代码如下:

<div class="msg"><a onclick="InsertQuote(this.parentNode.getElementsByTagName('CITE')[0].innerHTML,this.parentNode.getElementsByTagName('BLOCKQUOTE')[0].innerHTML);return false;" href="#comment">引用</a><cite>评论者</cite><blockquote>评论内容</blockquote><p>网站</p><p>时间</p></div>

看其引用按钮写法是

<a onclick="InsertQuote(this.parentNode.getElementsByTagName('CITE')[0].innerHTML,this.parentNode.getElementsByTagName('BLOCKQUOTE')[0].innerHTML);return false;" href="#comment">引用</a>

参数一的意思是在引用按钮代码的父级div(取最外围的div,如果是父级的父级,就要写两个parentNode.)中按顺序找到第一个cite标签(数列的序号是从0开始的,所以第一个也就是0),这里是先引用评论者的名称;参数二的意思是从引用按钮代码的父级div中按顺序找到第一个blockquote标签,这里引用的是评论内容。

PS:我已经尽可能说得很简单了,不明白再问吧。

相关推荐