PHP7中文手册2018 带注释 最新chm版
smarty模板中select选值使用html_options标签:
<select name=customer_id>
{html_options options=$cust_options selected=$customer_id}
</select>
实例:
后台文件:out.php
require('Smarty.php.class'); $smarty = new Smarty; $smarty->assign('cust_options', array( 1001 => 'Joe Schmoe', 1002 => 'Jack Smith', 1003 => 'Jane Johnson', 1004 => 'Charlie Brown')); $smarty->assign('customer_id', 1001); $smarty->display('out.tpl');
模板文件:out.tpl
<select name=customer_id> {html_options options=$cust_options selected=$customer_id} </select>
注意说明:$customer_id一定是数组中某个元素的键名,不是元素值
模板解析之后:
<select name=customer_id> <option value="1000">Joe Schmoe</option> <option value="1001" selected="selected">Jack Smith</option> <option value="1002">Jane Johnson</option> <option value="1003">Charlie Brown</option> </select>