这里好像看不出颜色 要清楚点的来这里看
http://www.webfort.cn/bbs/2007/3/30/...9fbb766e1d.htm
这里我说说如何用Webfort模板制作一个树形的菜单。
下面给出需要的代码,然后讲解
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>左边树</title>
<script language="javascript" type="text/javascript">
var isBottom;
function returnIsBottom(value){
switch(value.toLowerCase()){
case "0":
case "":
case "false":
return false;
default:
return true;
}
function expendNode(divName){
var src=document.getElementById(divName);
try{
src.style.display=src.style.display=="none"?"":"none";
}catch(e){//alert(e.message)
}
}
}
</script>
</head>
<body>
<webfort:ChannelList>
<webfort:ChannelCondition/>
<webfort:ChannelItemTemplate>
<div>
<script language="javascript" type="text/javascript">
isBottom=returnIsBottom('<webfort:ChannelField FieldName="IsBottom" />');
if(isBottom){
document.write('<img src="/Template/default/bbs/images/list.gif" /><a href="<webfort:ChannelField FieldName="FolderPath" />" target="frmMain"><webfort:ChannelField FieldName="ChannelAlias" /></a>');
}
else{
document.write('<img src="/Template/default/bbs/images/topic_t.gif" /><a href="#" onclick="expendNode(\'div<webfort:ChannelField FieldName="ChannelID" />\')"><webfort:ChannelField FieldName="ChannelAlias" /></a>');
}
</script>
</div>
<webfort:CallTemplate Name="Sub" />
</webfort:ChannelItemTemplate>
</webfort:ChannelList>
<br />
</body>
</html>
<webfort:Template Name="Sub">
<div style="margin-left:20px;" id='div<webfort:ChannelField FieldName="ChannelID" /> '>
<webfort:ChannelList>
<webfort:ChannelCondition/>
<webfort:ChannelItemTemplate>
<div>
<script language="javascript" type="text/javascript">
isBottom=returnIsBottom('<webfort:ChannelField FieldName="IsBottom" />');
if(isBottom){
document.write('<img src="/Template/default/bbs/images/list.gif" /><a href="<webfort:ChannelField FieldName="FolderPath" />" target="frmMain"><webfort:ChannelField FieldName="ChannelAlias" /></a>');
}
else{
document.write('<img src="/Template/default/bbs/images/topic_t.gif" /><a href="#" onclick="expendNode(\'div<webfort:ChannelField FieldName="ChannelID" />\')"><webfort:ChannelField FieldName="ChannelAlias" /></a>');
}
</script>
</div>
<webfort:CallTemplate Name="Sub" />
</webfort:ChannelItemTemplate>
</webfort:ChannelList>
</div>
</webfort:Template>
上面代码用到了三种模板标签:
webfort:ChannelList:此标签是列出子频道标签,根据条件列出子频道
webfort:ChannelField:此标签是输出频道的字段内容标签,根据后面的字段名输出频道字段
webfort:Template:此标签是模板模板标签,可以在其他任何地方调用此模板中定义的html代码
红色框中的代码是一个webfort:Template标签的模板体,在此模板体中使用了一个webfort:ChannelList标签来列出子频道,这里说明一下,任何模板在解析过程中都会有解析的环境,如:现在处在那个频道下、现在处在哪个文章下等等。模板体中列出了所有的子频道,并用js代码来判定是否是最底层频道,并在webfort:ChannelList的最后面调用此模板体,形成递归调用。蓝色框中的代码就比较简单,就是列出此频道环境下的子频道,并最后调用一下webfort:Template定义的模板体,调用模板体都是通过<webfort:CallTemplate Name="Sub" />代码来调用,后面的Name就是定义的模板体的名称。
上面这样的解释可能比较难以理解,不过如果用熟悉了webfort:ChannelList标签然后使用一下webfort:Template再来看这段代码,可能比较清楚。
上面这样的模板思路极度像是写了一个函数,然后供其他函数调用这么个概念。
上面的代码你放在任何模板中,都会输出子频道的无穷树。








如何用Webfort模板制作一个树形的菜单







平板模式