如何在禁用输入时更改< label>的颜色? [英] How can I change a <label>’s color when its input is disabled?

查看:78
本文介绍了如何在禁用输入时更改< label>的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些标签:

 < label> 
< input type =checkboxname =the_nameid =the_name/>标签文字
< / label>有时被禁用的

  $(#the_name)。prop('disabled',true); 

没问题,但我想更改标签文字颜色,是否可以使用Jquery和/或CSS?

解决方案

您可以通过选择父输入并添加到禁用控件时的值

  $(#the_name)prop('disabled' true).parent()。css({backgroundColor:'#fcc'}); 






此外,我认为标签是用来像这样:

 < label for =the_id>标签文字< / label& 
< input type =checkboxname =the_nameid =the_id/>
属性匹配<目标控件



的code> id ,在这种情况下,您可以选择 / code>属性并应用css,如下所示:

  $(#the_id) .prop('disabled',true); 
$('label [for = the_id]')。css({backgroundColor:'#fcc'});

请参阅fiddle for demo: http://jsfiddle.net/bq52X/


I have some labels like:

  <label>
     <input type="checkbox" name="the_name" id="the_name" /> Label text
  </label>

that sometimes are disabled

$("#the_name").prop('disabled', true);

No problem, but I would like to change label text color to make it more visible. Is it possible using Jquery and/or CSS?

解决方案

you can add a css rule to the label by selecting the parent of your input and adding to that at the time you disable the control

$("#the_name").prop('disabled', true).parent().css({backgroundColor:'#fcc'});


Additionally, I think label is meant to be used like this:

<label for="the_id">Label text</label>
<input type="checkbox" name="the_name" id="the_id" />

where the label's for attribute matches the id of the target control

in which case you could select the label by it's for attribute and apply css as you see fit - something like this:

$("#the_id").prop('disabled', true);
$('label[for=the_id]').css({backgroundColor:'#fcc'});

See fiddle for demo: http://jsfiddle.net/bq52X/

这篇关于如何在禁用输入时更改&lt; label&gt;的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆