简体   繁体   English

如果选中check_box,如何更改索引中的字体颜色?

[英]If check_box is checked how to change font color in index?

If the user checks off :good in the _result_fields.html.erb how can we change the :result_value & :date_value font color to green in the index? 如果用户在_result_fields.html.erb中选中:good ,如何将索引中的:result_value:date_value :result_value字体颜色更改为绿色

This is to give the user a visual reference for his quantified :results overtime. 这是为了给用户一个可视化的参考,以供他量化的超时:results

For example: 例如:

Averaged
Meditated (min)
1.4 Dec 2014
1.8 Jan 2015***
2.1 Feb 2015***
1.8 Mar 2015
  *** represents green font color. The User would have checked :good for these results in the form to make them green in the index.

Results being a nested attribute of quantifieds. 结果是量化的嵌套属性。

 class Result < ActiveRecord::Base belongs_to :user belongs_to :quantified default_scope { order('date_value DESC') } scope :good, -> { where(good: true) } scope :bad, -> { where(good: false) } end 

_result_fields.html.erb _result_fields.html.erb

 <div class="nested-fields"> <div class="form-group"> <%= f.text_field :result_value, class: 'form-control', placeholder: 'Enter Result' %> <br/> <%= f.date_select :date_value, :order => [:month, :day, :year], :with_css_classes => true, :class => "modular-date-field" %> <b><%= link_to_remove_association "Remove Result", f %></b> <div class="america3"> <label> Good: </label> <%= f.check_box :good %> </div> </div> </div> 

Quantifieds controller 量化控制器

 class QuantifiedsController < ApplicationController before_action :set_quantified, only: [:show, :edit, :update, :destroy] before_action :logged_in_user, only: [:create, :destroy] def index if params[:tag] @quantifieds = Quantified.tagged_with(params[:tag]) else @quantifieds = Quantified.joins(:results).all @averaged_quantifieds = current_user.quantifieds.averaged @instance_quantifieds = current_user.quantifieds.instance end end 

quantifieds/index.html.erb 量化的/ index.html.erb

 <script> window.fbAsyncInit = function() { FB.init({ appId : '1540372976229929', xfbml : true, version : 'v2.2' }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> <!-- Default bootstrap panel contents --> <div id="valuations" class="panel panel-default"> <div class="panel-heading"><h4><b>AVERAGE</b></h4></div> <% @averaged_quantifieds.each do |averaged| %> <div class="attempt"> <b><%= raw averaged.tag_list.map { |t| link_to t.titleize, tagquantifieds_path(t) }.join(', ') %> <%= link_to edit_quantified_path(averaged) do %> (<%= averaged.metric %>)</b> <% end %> <div class="red"> <ul> <% averaged.results.each do |result| %> <li> <b><%= result.result_value %></b>&nbsp;&nbsp; <%= result.date_value.strftime("%b %Y") %> </li> <% end %> </ul> </div> </div> <% end %> </div> <div class="valuations-button"> <%= link_to new_quantified_path, class: 'btn' do %> <b><span class="glyphicon glyphicon-plus"</span></b> <% end %> </div> <div class="fb-like" data-share="true" data-width="450" data-show-faces="true"> </div> <br> <!-- Default bootstrap panel contents --> <div id="valuations" class="panel panel-default"> <div class="panel-heading"><h4><b>INSTANCE</b></h4></div> <% @instance_quantifieds.each do |instance| %> <div class="attempt"> <b><%= raw instance.tag_list.map { |t| link_to t.titleize, tagquantifieds_path(t) }.join(', ') %> <%= link_to edit_quantified_path(instance) do %> (<%= instance.metric %>)</b> <% end %> <div class="red"> <ul> <% instance.results.each do |result| %> <li> <%= result.date_value.strftime("%b.%d.%y") %> &nbsp;&nbsp; <%= result.result_value %> </li> <% end %> </ul> </div> </div> <% end %> </div> <div class="valuations-button"> <%= link_to new_quantified_path, class: 'btn' do %> <b><span class="glyphicon glyphicon-plus"</span></b> <% end %> </div> 

Thank you so much for your time! 非常感谢您的参与!

you can use checked : 您可以使用checked:

input[type=checkbox]:checked + label {
  color: red;
}

Live Demo 现场演示

you can style whatever rule you want when the check box get checked 您可以在选中复选框时设置所需样式的样式

of course make sure your are not trying to select a parent element, there is no way to select a parent with CSS only 当然,请确保您没有尝试选择父元素,没有办法仅使用CSS选择父元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM