首页 > PHP开源 > 如何创建一个选择域和下拉菜单–kohana3使用手册

如何创建一个选择域和下拉菜单–kohana3使用手册

2011年3月9日 发表评论 阅读评论

Form::select() 方法能用来创建选择域或下拉菜单。它包含了一些定义选项和设置哪个选项被选中的参数。

echo Form::select(‘name’, array(

‘standard’=>’Standard Shipping’,

‘express’=>’Express Shipping’,

‘international’=>’International’,

));

将返回

<select name=”name”>

<option value=”standard”>Standard Shipping</option>

<option value=”express”>Express Shipping</option>

<option value=”international”>International</option>

</select>

增加第三个参数来定义哪个选项被选中

echo Form::select(‘name’, array(

‘standard’=>’Standard Shipping’,

‘express’=>’Express Shipping’,

‘international’=>’International’,

), ‘express’);

将返回

<select name=”name”>

<option value=”standard”>Standard Shipping</option>

<option value=”express” selected=”selected”>Express Shipping</option>

<option value=”international”>International</option>

</select>

第4个参数接受一个属性数组

echo Form::select(‘name’, array(

‘standard’=>’Standard Shipping’,

‘express’=>’Express Shipping’,

‘international’=>’International’,

), ‘express’, array(‘disabled’=>TRUE));

将返回

<select name=”name” disabled=”1″>

<option value=”standard”>Standard Shipping</option>

<option value=”express” selected=”selected”>Express Shipping</option>

<option value=”international”>International</option>

</select>

配置组

数组配置(第2个参数),键定义了一个配置组的标签,值就是配置组成的数组

echo Form::select(‘product’, array(

‘Fruits’ => array(

‘apple’ => ‘Apple’,

‘orange’ => ‘Orange’,

‘plum’ => ‘Plum’

),

‘Vegetables’ => array(

‘lettuce’ => ‘Lettuce’,

‘parsley’ => ‘Parsley’,

‘cucumber’ => ‘Cucumber’

)

));

…过程…

<select name=”product”>

<optgroup label=”Fruits”>

<option value=”apple”>Apple</option>

<option value=”orange”>Orange</option>

<option value=”plum”>Plum</option>

</optgroup>

<optgroup label=”Vegetables”>

<option value=”lettuce”>Lettuce</option>

<option value=”parsley”>Parsley</option>

<option value=”cucumber”>Cucumber</option>

</optgroup>

</select>

分类: PHP开源 标签:
  1. 本文目前尚无任何评论.