Smarty之html_options使用心得
2009-12-16 16:48
453 查看
模板部分
<select name="select2" size="4" id="alluser" style="width:300px; height:200px;" multiple="multiple">
<{html_options options=$sysUser
}>
</select>
程序部分
$sql_sysuser = "select * from tuser where tuser_status='1' order by tuser_truename";
$rs_sysuser = $db->sql_query($sql_sysuser);
while($row_sysuser = $db->sql_fetchrow($rs_sysuser)){
$usersys
[$row_sysuser['tuser_name']
]=$row_sysuser['tuser_truename']
;
}
可见smarty的html_options接受的其实是一个数组,并且这个数组还是有点要求滴~
数组的键值将是option的value
值,而数组的值则将是option的
显示值
,如果需要初始状态某个值是出于选择状态,那么
程序部分
$smarty->assign('customer_id
', 1001);
模板部分
<select name=customer_id>
{html_options options=$cust_options selected
=$customer_id
}
</select>
html_options还有一种用法,option的value和显示是分开的
,这样方便处理其他的一些情况
具体用法如下
index.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('index.tpl');
index.tpl:
<select name=customer_id>
{html_options values=$cust_ids
selected=$customer_id output=$cust_names
}
</select>
<select name="select2" size="4" id="alluser" style="width:300px; height:200px;" multiple="multiple">
<{html_options options=$sysUser
}>
</select>
程序部分
$sql_sysuser = "select * from tuser where tuser_status='1' order by tuser_truename";
$rs_sysuser = $db->sql_query($sql_sysuser);
while($row_sysuser = $db->sql_fetchrow($rs_sysuser)){
$usersys
[$row_sysuser['tuser_name']
]=$row_sysuser['tuser_truename']
;
}
可见smarty的html_options接受的其实是一个数组,并且这个数组还是有点要求滴~
数组的键值将是option的value
值,而数组的值则将是option的
显示值
,如果需要初始状态某个值是出于选择状态,那么
程序部分
$smarty->assign('customer_id
', 1001);
模板部分
<select name=customer_id>
{html_options options=$cust_options selected
=$customer_id
}
</select>
html_options还有一种用法,option的value和显示是分开的
,这样方便处理其他的一些情况
具体用法如下
index.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('index.tpl');
index.tpl:
<select name=customer_id>
{html_options values=$cust_ids
selected=$customer_id output=$cust_names
}
</select>
相关文章推荐
- Smarty之html_options使用心得
- Smarty之html_options使用心得
- smarty中的html_options方法使用简介
- html:optionsCollection 的 filter 过滤属性使用心得 - 解决空格不能显示的问题
- Struts中html:options的使用
- <html:select>,<html:option>,<html:optionsCollection>标签使用
- MVC Html.BeginForm 使用心得
- html:link中的name,paramId,paramName和paramProperty四个属性的使用心得
- php Smarty 使用手册和一些常见问题,使用心得
- Struts 中 html:options 的使用
- html:link中的name,paramId,paramName和paramProperty四个属性的使用心得
- DataTables 控件使用和心得 (2) - 参数Options
- DataTables 控件使用和心得 (2) - 参数Options中文说明
- html+js+PHP(使用了smarty模板技术)+mysql实现二级动态下拉列表(select)
- struts中htmlselect标签和htmloptions 的使用
- gcov、lcov与genhtml 使用心得
- QT QWebKit使用心得(Qwebkit与Html之间通信)
- html:link中的name,paramId,paramName和paramProperty四个属性的使用心得
- PHP Smarty 函数插件(自定义函数)html_options
- J2EE]Structs - HTML、Bean、Logic、Template和Nested标签库总结、心得和使用详