简体   繁体   English

更改文本框背景颜色有条件

[英]Changing textbox backcolor Conditionally

I have a few textboxes in an aspx page. 我在aspx页面中有几个文本框。 i would like to change the textbox color to yellow if they are enabled. 如果启用它,我想将文本框颜色更改为黄色。 I can do it individually for each textbox. 我可以为每个文本框单独完成。 But is there a way where I can get all the textbox collection of a page and check their enabled property and assign the backcolor? 但是有没有办法让我可以获取页面的所有文本框集合并检查其启用的属性并分配背景颜色?

Using JQuery Assuming they share a common class "textboxes" 使用JQuery假设他们共享一个共同的类“文本框”

if (($(".textboxes").attr("enabled")){
    $(".textboxes").css("background-color","green")}
else{
    $(".textboxes").css("background-color","red")}
}

or for earlier javascripts 或者早期的javascripts

if (($(".textboxes").prop("enabled")){
    $(".textboxes").css("background-color","green")}
else{
    $(".textboxes").css("background-color","red")}
}

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

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