首页 > Web开发 > 详细

夺命雷公狗---Smarty NO:19 html_options函数

时间:2015-12-09 18:58:01      阅读:179      评论:0      收藏:0      [点我收藏+]

功能:把数组转化为option下拉选项

基本语法:

<select name=customer_id>

{html_options values=$cust_ids  selected=$customer_id  output=$cust_names}

</select>

参数说明:

output:要遍历输出的数组

values:每一个下拉选项的value值,要求是一个数组

selected:被选中的元素,要求也是一个数组

 

demo6.html示例代码:

 

<!DOCTYPE html>
<html>
<head>
<meta charset=’utf-8′>
<title></title>
</head>
<body>
<select multiple=”multiple” name=”like”>
{html_options output=$output values=$values selected=$checked}
</select>
</body>
</html>

 

 

demo6.php示例代码:

 

<?php
require “smarty/Smarty.class.php”;
$smarty = new Smarty();
//output假如是从数据库中读取出来的数据
$output = array(‘php’,’apache’,’mysql’,’linux’);
$values = array(1,2,3,4);//依次对应上面的值得
$checked = array(1,3);
$smarty -> assign(‘output’,$output);
$smarty -> assign(‘values’,$values);
$smarty -> assign(‘checked’,$checked);
$smarty -> display(‘demo6.html’);

 

夺命雷公狗---Smarty NO:19 html_options函数

原文:http://www.cnblogs.com/leigood/p/5033422.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!