【问题标题】:CakePHP - How to add attributes to individual radio buttons?CakePHP - 如何为单个单选按钮添加属性?
【发布时间】:2013-02-04 03:54:35
【问题描述】:

如何将单个属性添加到单选按钮?据我所知,CakePHP 只允许您向组中的所有单选按钮添加相同(有限)的属性。

例如,关于如何生成这个的任何想法?

<input type="radio" checked="checked" value="0" name="data[MyModel][field]" id="custom-id-1" class="custom-class-1" data-something="test1">
<label for="custom-id-1">Test 1</label>
<input type="radio" checked="checked" value="0" name="data[MyModel][field]" id="custom-id-2" class="custom-class-2" data-something="test2">
<label for="custom-id-2">Test 2</label>

【问题讨论】:

    标签: cakephp radio-button


    【解决方案1】:

    试试这个:

    $options = array('1' => 'Test 1'); <br> $attributes =
    array('value'=>'1','class'=>'custom-class-1','id'=>'custom-id-1','data-something'=>'test1');
    
    echo $this->Form->radio('field_name1', $options, $attributes);
    
    ---------------------
    
    
    $options = array('1' => 'Test 2'); <br> $attributes =
    array('value'=>'1','class'=>'custom-class-2','id'=>'custom-id-2','data-something'=>'test2');
    
    echo $this->Form->radio('field_name2', $options, $attributes);
    

    【讨论】:

      【解决方案2】:

      echo $this-&gt;Form-&gt;input('title', array('type' =&gt; 'radio', 'class' =&gt; 'custom-class', 'atributeName' =&gt; 'attributeValue'));

      【讨论】:

      • 你有没有生成一组带有模型关联的单选按钮的例子?你能举个例子来生成我发布的 HTML 吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-27
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 2011-04-27
      相关资源
      最近更新 更多