近来偶有需求,需要相册里每一个图片都配上一段文字说明,研究了一下相册的模板文件,发现这个相册的代码里似乎直接就有这一功能,不信你自己看
<div id="flashCff"></div>
<div id="contTxt"></div>
<div id="PGViframe"></div>
看见了吧,经常写代码的人几乎会有这么一种“嗅觉”,毫无疑问,我拥有这种敏锐的“嗅觉”,它(conTxt)告诉我,这里似乎就是插入文字的;猜想完成,进行下一步
<!--相册相关文件 -->
<link href="{aspcms:sitepath}/Css/Album.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="{aspcms:sitepath}/Js/jquery.js" type="text/javascript"></script>
<script language="JavaScript" src="{aspcms:sitepath}/Js/Select.js" type="text/javascript"></script>
<script type="text/javascript">
var imgurl="{aspcms:sitepath}/Images/Album/";
var GroupjsUrl = "{aspcms:sitepath}/Js/Album.js";
</script>
<!--相册相关文件 -->
同样是相册模板文件的内容,可以看见调用了一个album.js的JS文件,在这里面可以很容易发现,上面那个contxt确实有填充控制的!也就是存在控制它输出的JS,不怕没调用了。
在浏览器里右键查看生成了HTML页面的代码,看看相册页面的代码,主要是看JS那一部分,看他怎么调用的
发现:
<script> var isLoadData = false; var photoJson = [{showtit:'',showtxt:'',smallpic:'/upLoad/album/month_1210/201210301629231904.jpg','bigpic':'/upLoad/album/month_1210/201210301629231904.jpg'},
{showtit:'',showtxt:'',smallpic:'/upLoad/album/month_1210/201210301629309590.jpg','bigpic':'/upLoad/album/month_1210/201210301629309590.jpg'},
{showtit:'',showtxt:'',smallpic:'/upLoad/album/month_1210/201210301629376951.jpg','bigpic':'/upLoad/album/month_1210/201210301629376951.jpg'},
{showtit:'',showtxt:'',smallpic:'/upLoad/album/month_1210/201210301629511611.jpg','bigpic':'/upLoad/album/month_1210/201210301629511611.jpg'},
{showtit:'',showtxt:'',smallpic:'/upLoad/album/month_1210/201210301629572399.jpg','bigpic':'/upLoad/album/month_1210/201210301629572399.jpg'}]; isLoadData = true; </script>
很明显了,调用是通过数组 photoJson产生的。它的值是标签[content:pics]调用的,在DW等编辑软件中全站搜索关键词“pics”(最初怀疑是在主类文件AspCms_MainClass.asp中,发现没有这个解析,于是才全站搜索),找到该解析在AspCms_templateFun.asp文件里,打开它
发现:
dim imagepath if not isnul(rsObj("imagepath")) then dim i,images images=split(rsObj("imagepath"),"|") for i=0 to ubound(images) if not isnul(images(i)) then if instr(rsObj("IndexImage"),"http://")>0 then imagepath=imagepath&"{showtit:'',showtxt:'',smallpic:'"&images(i)&"','bigpic':'"&images(i)&"'}" else imagepath=imagepath&"{showtit:'',showtxt:'',smallpic:'"&images(i)&"','bigpic':'"&images(i)&"'}" end if if i<>ubound(images) then imagepath=imagepath&"," end if next end if
没错,应该看的很明白了,就是这一段负责的,可以高兴的发现开始的猜测是正确的(showtxt存在),可是很容易发现并不能太高兴,因为它默认都是空值
现在知道了,解决这里,就可以实现显示文字。
解决方法
1.在AspCms_templateFun.asp文件中添加一个去HTML标签的函数
Function RemoveHTML(strText) Dim RegEx Set RegEx = New RegExp RegEx.Pattern = "<[^>]*>" RegEx.Global = True RemoveHTML = RegEx.Replace(strText, "") End Function
2.改写一下imagepath里的那个文字空值部分,改后如下
dim imagepath if not isnul(rsObj("imagepath")) then dim i,images,cctxt images=split(rsObj("imagepath"),"|") cctxt=split(RemoveHTML(rsObj("Content")),"|") for i=0 to ubound(images) if not isnul(images(i)) then if instr(rsObj("IndexImage"),"http://")>0 then imagepath=imagepath&"{showtit:'',showtxt:'',smallpic:'"&images(i)&"','bigpic':'"&images(i)&"'}" else 'imagepath=imagepath&"{showtit:'',showtxt:'',smallpic:'"&images(i)&"','bigpic':'"&images(i)&"'}" imagepath=imagepath&"{showtit:'',showtxt:'"&cctxt(i)&"',smallpic:'"&images(i)&"','bigpic':'"&images(i)&"'}" end if if i<>ubound(images) then imagepath=imagepath&"," end if next end if
*注意划线的部分,这里就不解释了,太明了了。
3.添加相册的时候,有多少张图片,就配多少段文字,每段文字之间加上“|”,这一步稍微注意下就好,文字段数跟图片张数要对应(其实通过这一步就会发现,如果在后台添加相册那里自增一个文本框专门用来输入文字,也就不用上面那个去HTML标签的函数了,不过考虑的可能文字长短不一,太长的话文本框有限制,还是用了这种方法!)
4.完成。
----------------------个人原创,有问题可以留言!