$policy.status 3次循环的值都为1,但是无法进行 radio只选定最后一个 “开” ,其他两个是未选定的状态,这是为什么?
{{foreach from=$policyInfo item=policy}}
{{if $policy.status eq "1"}}
<th><p>开:<input type="radio" checked="checked" name="single1" value="1" /></p><p>关:<input type="radio" name="single2" value="0" /></p></th>
{{else}}
<th><p>开:<input type="radio" name="single1" value="1" /></p><p>关:<input type="radio" checked="checked" name="single2"value="0" /></p></th>
{{/if}}
{{/foreach}}

解决方案 »

  1.   

    html里的单选 radio 标签, 只能选一个, 如果所有都强行选择 , 就好像你拿鼠标在 radio上分别去点,当然, 单选, 只能是最后一个有效, 
    如果你要多选 的话, 用checkbox复选框。 
      

  2.   

    你这种只能在给smarty处理之前处理好checked的样式
    $checked_key = -1;
    foreach($policyInfo as $k => $v) {    // 判定当前索引是否要选择
        if($v['status'] == '1') {
    $checked_key = $k;
    } // 标志位初始化
    $policyInfo[$k]['checked'] = false;}if(isset($policyInfo[$checked_key]) {
    $policyInfo[$checked_key]['checked'] = true;
    }然后smarty 中 判断{{foreach from=$policyInfo item=policy}}
    {{if $policy.checked}}
    <th><p>开:<input type="radio" checked="checked" name="single1" value="1" /></p><p>关:<input type="radio" name="single2" value="0" /></p></th>
    {{else}}
    <th><p>开:<input type="radio" name="single1" value="1" /></p><p>关:<input type="radio" checked="checked" name="single2"value="0" /></p></th>
    {{/if}}
    {{/foreach}}