【问题标题】:Radio button checked but not showing as checked单选按钮已选中但未显示为已选中
【发布时间】:2017-12-28 06:46:17
【问题描述】:

我的表格由 15 条记录组成,分为 2 页,但是,第一页中的那些单选按钮将不会被选中,如下图所示。

Output

这里是查看页面中使用的代码:

<?php foreach($rights->result() as $row){
      echo "<label class='radio-inline'><input type='radio' name='rightRBtn[".$perm_id."]' value='$row->id'".(($row->id == $right_id) ? " checked='checked'":'')." />" . $row->description."</label>";     
}?>

浏览器源视图显示单选按钮框实际上也被选中。

&lt;td&gt;&lt;label class='radio-inline'&gt;&lt;input type='radio' name='rightRBtn[22]' value='0' checked='checked' /&gt;none&lt;/label&gt;&lt;label class='radio-inline'&gt;&lt;input type='radio' name='rightRBtn[22]' value='1' /&gt;view&lt;/label&gt; &lt;/td&gt;

有谁知道问题出在哪里?

【问题讨论】:

  • 是的,但是输出还是一样的。
  • array(2) { [0]=> object(stdClass)#51 (2) { ["id"]=> string(1) "0" ["description"]=> string (4) "none" } [1]=> object(stdClass)#52 (2) { ["id"]=> string(1) "1" ["description"]=> string(4) "view" } } 这是 $right_id --> 1
  • 会是引导程序问题还是数据表问题?因为我尝试使用纯 html 代码,单选按钮也没有选中。
  • 不,它在本地运行。
  • 没关系,谢谢你的帮助。

标签: php html codeigniter datatables-1.10


【解决方案1】:

通过应用简单的if-else 来简化foreach() 循环代码,并避免一些不必要的引号调整。

<?php foreach($rights->result() as $row){
  if($row->id == $right_id){
    echo "<label class='radio-inline'><input type='radio' name='rightRBtn[".$perm_id."]' value='$row->id' checked/>" . $row->description ."</label>"; 
  }else{
    echo "<label class='radio-inline'><input type='radio' name='rightRBtn[".$perm_id."]' value='$row->id'/>" . $row->description ."</label>"; 
  }   
}
?>

在我的本地端它正在工作:-

我使用的代码:-https://prnt.sc/ht9mzb(我只是使用 json_decode 和 json_encode 使其成为你所拥有的 stdclassobject 数组)

输出:-https://prnt.sc/ht9m1n

【讨论】:

    【解决方案2】:

    我对这个问题的解决方法是删除responsive: true

    $('#dataTables-example').DataTable({
    //            responsive: true 
    });
    

    【讨论】:

      猜你喜欢
      • 2011-06-20
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多