为什么复选框是检查而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)]
谢谢你的作品! – Orsay