html_options函數登入

html_options函數

此函數可以指定哪些元素被選定. 要麼必須指定values 和ouput 屬性,要麼指定options 替代.

如果給定值是數組,將作為OPTGROUP 處理,且支援遞歸. 所有的輸出與 XHTML 相容. 

#如果指定了可選屬性name,則該選項清單將被置於<select name="groupname"></select>標籤對中. 如果沒有指定,那麼只產生選項列表.

上表未提到的其它參數在<select> ; 標籤中以"名稱/屬性"對的方式顯示. 如果沒有指定可選屬性name 這些參數將被忽略.

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 => '喬·施莫',
1002 => '傑克·史密斯',
1003 => '簡·約翰遜',
1004 => '查理布朗'));
$smarty->分配('customer_id', 1001);
$smarty->display('test.html');


#test. html:



##<選擇名稱=customer_id> <選項值=“1000”>Joe Schmoe <選項值=“1001”selected=“selected”> ;傑克史密斯</選項> ;
<選項值=“1002”>簡·約翰遜</選項>
<選項值=“1003”>查理·布朗</選項>
< /選擇>



下一節

<?php echo "html_options函数";
章節課件