ASPCMS相册 实现每张图片对应一段文字

近来偶有需求,需要相册里每一个图片都配上一段文字说明,研究了一下相册的模板文件,发现这个相册的代码里似乎直接就有这一功能,不信你自己看

<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.完成。

 

 

----------------------个人原创,有问题可以留言!

转载于:https://www.cnblogs.com/ss159/archive/2012/11/01/2750000.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值