为什么复选框是检查而HTML值=假

问题描述:

当我去编辑页面我所有的复选框被选中,而当我看在HTML我有一些则设置为false:为什么复选框是检查而HTML值=假

<input checked="false" class="hidden" id="cover_inspiration_image_ids" name="cover[inspiration_image_ids][]" type="checkbox" value="68"> 

我可以”不明白为什么checked值不起作用。 我也试图与checked="checked"

我试图用jQuery:$(".hidden").prop('checked')并返回true

这是我的代码:

盖/ _form

- @inspiration_images.each do |img| 
    - next if img.image.path.nil? 
    .w-col.w-col-2.w-col-small-4.w-col-tiny-6 
     label 
     INPUT[type="checkbox" name="cover[inspiration_image_ids][]" id='cover_inspiration_image_ids' value="#{img.id}" class="hidden" checked="#{check_status(img, @cover)}"] 
      .image-cov-pick 
      = cl_image_tag(img.image.path, height: 190, class: 'img-to-pick').html_safe 
      .white 

cover_helper

module CoversHelper 
    def check_status(image, cover) 
    cover.inspiration_image_ids && cover.inspiration_image_ids.include?(image.id) 
    end 
end 

能不能请你传递价值Boolean而不是String

checked="#{check_status(img, @cover)}" 
#to 
checked=check_status(img, @cover) 

全码

INPUT[type="checkbox" name="cover[inspiration_image_ids][]" id='cover_inspiration_image_ids' value="#{img.id}" class="hidden" checked=check_status(img, @cover)] 
+0

谢谢你的作品! – Orsay

如果你不想被选中的复选框,就不要渲染其checked属性根本没有任何价值。

相关:What values for checked and selected are false?