dedecms里标签runphp实现变量自加自减,dede的channel标签嵌套实现数字序列
利用了dedecms的标签嵌套{dede:channelartlist}和{dede:channel}及{dede:php}三个标签的嵌套,实现了省市的二级联动菜单,具体的代码如下,就不多说了。
重点的代码提示下:
{dede:php} global $abc; $abc = 0; {/dede:php}
设置并声明全局变量
subcat[[field:global name=abc runphp=yes] global $abc; $abc=$abc+1;echo $abc;[/field:global]] = new Array('[field:reid/]','[field:typename/]','[field:typelink/]')
在文章列表里实现变量的自加功能
<!-- 二级联动 Start --> <script language="JavaScript"> <!-- var subcat = new Array(); {dede:php} global $abc; $abc = 0; {/dede:php} {dede:channelartlist typeid='37'} {dede:channel type='son' noself='yes'} subcat[[field:global name=abc runphp=yes] global $abc; $abc=$abc+1;echo $abc;[/field:global]] = new Array('[field:reid/]','[field:typename/]','[field:typelink/]') {/dede:channel} {/dede:channelartlist} //subcat[1] = new Array('10','2','=2') function changeselect1(locationid) { document.form1.s2.length = 0; document.form1.s2.options[0] = new Option('==请选择==',''); for (i=0; i<subcat.length; i++) { if (subcat[i][0] == locationid) {document.form1.s2.options[document.form1.s2.length] = new Option(subcat[i][1], subcat[i][2]);} } } function gourl(url) { window.location.href = url; } //--> </script> <form name="form1"> <select name="s1" onChange="changeselect1(this.value)"> <option>==请选择==</option> {dede:channelartlist typeid='37'} <option value="{dede:field name='id'/}">{dede:field name='typename'/}</option> {/dede:channelartlist} </select> <select name="s2" onChange="gourl(this.value);"> <option>==请选择==</option> </select> </form> <!-- 二级联动 Over --> |