+ -
当前位置:首页 → 问答吧 → 帮帮忙吧 复选框取值问题

帮帮忙吧 复选框取值问题

时间:2010-08-17

来源:互联网

如这样的几个checkbox  
  <td><input   type="checkbox"   class="checkbox"   name="jt[]"   value="1"   />  
                                  Any   </td>  
                              <td><input   type="checkbox"   class="checkbox"   name="jt[]"   value="2"   />  
                                  Contract</td>  
                          </tr>  
                          <tr>  
                              <td><input   type="checkbox"   class="checkbox"   name="jt[]"   value="3"   />  
                                  Permanent</td>  
                              <td><input   type="checkbox"   class="checkbox"   name="jt[]"   value="4"   />  
                                  Temporary/Fixed   Term   </td>  
                          </tr>  
                          <tr>  
                              <td><input   type="checkbox"   class="checkbox"   name="jt[]"   value="5"   />  
                                  Part   -Time   </td>  
  我把checkbox的value值存入了数据库,如选了1、4、5就存如到一个字段里为1,4,5然而我需要在修改这个页面的时候,从数据库里把值读出来,然后让checkbox该选中的处于选中状态。 这个怎么弄,现在我就是不会读,插入可以。插入正常

作者: liuzhaojun   发布时间: 2010-08-17

很简单啊,假定查询出来选中的值为$row['checked'] = 1,4,5;
复制代码
  1. <?php $checked = explode(',', $row['checked']);?>
  2.   <td><input type="checkbox" class="checkbox" name="jt[]" value="1"<?php if (in_array('1', $checked)) echo ' checked="checked"';?> /> Any</td>  
  3.   <td><input type="checkbox" class="checkbox" name="jt[]" value="2"<?php if (in_array('2', $checked)) echo ' checked="checked"';?> /> Contract</td>  
  4. </tr>  
  5. <tr>  
  6.   <td><input type="checkbox" class="checkbox" name="jt[]" value="3"<?php if (in_array('3', $checked)) echo ' checked="checked"';?> /> Permanent</td>  
  7.   <td><input type="checkbox" class="checkbox" name="jt[]" value="4"<?php if (in_array('4', $checked)) echo ' checked="checked"';?> /> Temporary/Fixed Term</td>  
  8. </tr>  
  9. <tr>  
  10.   <td><input type="checkbox" class="checkbox" name="jt[]" value="5"<?php if (in_array('5', $checked)) echo ' checked="checked"';?> /> Part -Time</td>

作者: riyan   发布时间: 2010-08-17

你能把你的代码改成smarty的形式吗?我用的是smarty

作者: liuzhaojun   发布时间: 2010-08-17