Smarty中内置标签 - 选择按钮的使用

博客介绍了Smarty中内置的函数类型标签,包括将数组遍历成单选按钮组、复选按钮组和下拉列表框的标签使用方法,如{ts:html_radios}、{ts:html_checkboxes}、{ts:html_options}等,并说明了各参数含义,还提及在PHP文件中获取前台HTML文件的值。

函数类型的标签(smarty中内置标签):

    Array("语文","数学","英语","历史")  遍历成四个单选按钮 组成的按钮组

    <input type="radio" name="" value="" checked="">按钮名称

 

  单选按钮:

    {ts:html_radios name="" values="" options="" output="" separator=""  checked=""}

    Name:单选按钮组名字

    Values:单选按钮的value值组成的一维索引数组

    Output:单选按钮的文本信息组成的一维索引数组

    Options: 以value作为键名或者索引,以output作为数组元素组成的一维关联数组

    Checked:被选中的单选按钮的value值

    Separator: 设置单选按钮和单选按钮中间的格式标签

 

  复选按钮组:

    {ts:html_checkboxes name="" values="" options="" output="" separator=""  checked=""}

    Checked: 被选中的复选按钮组组成的一维索引数组

    其他值与单选按钮相同

 

  下拉列表框:

    {ts:html_options name="" values="" options="" output="" selected=""}

 

  【radios.php】

<?php
require_once("./smarty.inc.php");
$values = array('1001','1002','1003','1004');
$outputs = array('Chinese','Math','English','History');
$options = array('1001'=>'Chinese','1002'=>'Math','1003'=>'English','1004'=>'History');
$checked = 1003;
$checkeds = array('1001','1004');

$tpl -> assign("values",$values);
$tpl -> assign("outputs",$outputs);
$tpl -> assign("options",$options);
$tpl -> assign("checked",$checked);
$tpl -> assign("checkeds",$checkeds);

$tpl -> display("radios.html");
?>

  【radios.html】

{ts:html_radios name="c1" values=$values output=$outputs checked=$checked}
<hr/>
{ts:html_radios name="c2" options=$options checked=$checked}
<hr/>
{ts:html_radios name="c3" options=$options checked=$checked separator="<br/>"}
<hr/>
<hr/>
{ts:html_checkboxes name="c4" values=$values output=$outputs checked=$checkeds}
<hr/>
{ts:html_checkboxes name="c5" options=$options checked=$checkeds}
<hr/>
{ts:html_checkboxes name="c6" options=$options checked=$checkeds separator="<br/>"}

<hr/>
<hr/>
{ts:html_options name="c7" values=$values output=$outputs selected=$checked}
<hr/>
{ts:html_options name="c8" options=$options selected=$checked}
<hr/>
{ts:html_options name="c9" options=$options selected=$checked}

#在radios.php中获取前台radios.html中的值#

 

转载于:https://www.cnblogs.com/shuo-128/p/6869144.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值