利用Smarty模板技术设计一定范围内奇偶数的输出
来源:互联网 发布:windows核心编程 源码 编辑:程序博客网 时间:2024/05/29 16:58
num.html
<!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>foreach与section的应用</title>
<script language="javascript" type="text/javascript">
function submit_even(){
document.getElementById('num_scope').action="num.php?num=even";
document.getElementById('num_scope').submit();
}
function submit_odd(){
document.getElementById('num_scope').action="num.php?num=odd";
document.getElementById('num_scope').submit();
}
function submit_else(){
var num= document.getElementById('c_num').value;
document.getElementById('num_scope').action="num.php?num="+num;
document.getElementById('num_scope').submit();
}
</script>
</head>
<body>
<form action="" method="post" id="num_scope">
请输如数字范围:
从:<input type="text" name="num_start" size="4" />到<input type="text" name="num_end" size="4" /><br />
</form>
<form action="" method="post" id="customer_num">
输出能被<input type="text" name="num" id="c_num" size="6" />整除的数:
</form>
<input type="button" value="整除输出" onclick="submit_else()" />
<input type="button" value="列出所有的偶数" onclick="submit_even()" />
<input type="button" value="列出所有的奇数" onclick="submit_odd()" />
</body>
</html>
num.php
<?php
$start = $_POST['num_start'];
$end = $_POST['num_end'];
$num_cate = $_GET["num"];
$array = array();
for($i=$start;$i<=$end;$i++){
$array[]=$i;
}
//print_r($array);
include 'libs/Smarty.class.php';
$smarty=new Smarty();
$smarty->template_dir="demo/templates";
$smarty->compile_dir="demo/templates_c";
$smarty->config_dir="demo/config";
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->assign('array',$array);
$smarty->assign('num_cate',$num_cate);
$smarty->display('num.tpl');
num.tpl
<!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>foreach与section的应用</title>
</head>
<body>
<{if $num_cate eq "even"}>
<{foreach from=$array item=value name="e"}>
<{if $value is even}>
数组中第<{$smarty.foreach.e.iteration}>个偶数是:<{$value}><br />
<{/if}>
<{/foreach}>
<{elseif $num_cate eq "odd"}>
<{section name="odd" loop=$array}>
<{if $array[odd] is odd}>
数组中第<{$smarty.section.odd.index}>个奇数是:<{$array[odd]}><br />
<{/if}>
<{/section}>
<{else}>
<{section name="el" loop=$array}>
<{if $array[el]%$num_cate==0}>
数组中第<{$smarty.section.el.index}>个能被<{$num_cate}>整除的数是:<{$array[el]}><br />
<{/if}>
<{/section}>
<{/if}>
</body>
</html>
- 利用Smarty模板技术设计一定范围内奇偶数的输出
- 输出一定范围内的奇偶数(foreach/section/if_elseif_else)
- OJ 2691: 输出一定范围内的素数
- C语言---一定范围内的“完数”
- Java生成一定范围内的浮点数
- 第20周-输出一定范围内的素数
- 求一定范围内质数的个数 并换行输出
- 输出指定范围内的素数并验证一定范围内的歌德巴赫猜想
- 输出奇偶数
- smarty模板中标签的输出方式
- 取一定范围内的随机数!
- 生成 一定范围内的随机数
- 显示一定范围内的素数
- 筛检法求一定范围内的素数
- 生成一定范围内的随机数
- 一定范围内的素数个数
- 求一定范围内的素数
- Smarty-案例(判断奇偶数(1))
- 变量调节器
- Smarty__if
- Map检测输入相同字符串的个数,
- smarty模版基础
- MYSQL的相关知识总结
- 利用Smarty模板技术设计一定范围内奇偶数的输出
- 乱码问题
- 错误与异常处理
- JavaScript百度百科
- mysql复习
- 最常见的php面试题
- php 图像处理
- XML
- smarty模板技术