如何在我的选择菜单选项标签中添加其他属性?像这样:
<select class="test" name="data[Test][test]">
<option value="1" data-price="100">My Option</option>
</select>
如何添加data-price="100"
?
我尝试了类似的东西,但它不起作用:
<?php
echo $this->Form->select('test', $options, null, array(
'class' => 'test',
'options' => array(
'data-price' => 100
)
));
?>
答案 0 :(得分:4)
检查一下: http://www.dereuromark.de/2012/03/01/some-new-crazy-cakephp-tricks/
“为某些选择选项设置其他属性”
答案 1 :(得分:3)
you can try this
echo $this->Form->input('test', array(
'options' => array(
1=>array(
'data-price' => 100,
'value' => '1',
'name' => 'My Option'
)),'class' => 'test')
);
答案 2 :(得分:2)
你可以这样做:
$options = array(
...
array('name' => 'United states', 'value' => 'USA', 'title' => 'the title that you want', 'class' => 'something'),
array('name' => 'USA', 'value' => 'USA', 'title' => 'the other title that you want', 'class' => 'otherthing'),
);
echo $this->Form->input('test', array('type'=>'select', 'options'=>$options));
答案 3 :(得分:0)
您必须手动构建选择HTML