html_options函數(shù)
該函數(shù)可以指定哪些元素被選定. 要么必須指定 values 和 ouput 屬性,要么指定 options 替代.
如果給定值是數(shù)組,將作為 OPTGROUP 處理,且支持遞歸. 所有的輸出與 XHTML 兼容.?
如果指定了可選屬性 name,該選項(xiàng)列表將將被置于<select name="groupname"></select>標(biāo)簽對(duì)中. 如果沒(méi)有指定,那么只產(chǎn)生選項(xiàng)列表.
上表未提到的其它參數(shù)在 <select> 標(biāo)簽中以"名稱/屬性"對(duì)的方式顯示. 如果沒(méi)有指定可選屬性 name 這些參數(shù)將被忽略.
eg1:
test.php:
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->assign('cust_ids', array(1000,1001,1002,1003));
$smarty->assign('cust_names', array('Joe Schmoe','Jack Smith','Jane
Johnson','Carlie Brown'));
$smarty->assign('customer_id', 1001);
$smarty->display('test.html');
test.html:
<select name=customer_id>
{html_options values=$cust_ids selected=$customer_id output=$cust_names}
</select>
eg2:
test.php:
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->assign('cust_options', array(
1001 => 'Joe Schmoe' ,
1002 => '杰克·史密斯',
1003 => '簡(jiǎn)·約翰遜',
1004 => '查理·布朗'));
$smarty->分配('customer_id', 1001);
$ smarty->display('test.html');
test.html:
輸出:?