使用 jQuery 更改背景颜色
我有一个带有多个下拉菜单的表单...我想在禁用可见下拉菜单时将其背景颜色设置为灰色。所有这些下拉菜单的 id 均以 usrControl 开头。这是我到目前为止所拥有的。
$('select[id ^= "usrControl"]:visible').each(function(){
this.css("background-color")
});
不知道如何获取禁用/启用的选择器。
提前致谢
Protected _picklistColorScriptText As String = "$(document).ready(function(){ " + _
"$('[id ^= ""usrControl""]:visible:disabled').css(""background-color"", '#DCDCDC'); " + _
"$('[id ^= ""usrControl""]:visible:enabled').css(""background-color"", '#FFFFFF');" + _
"});"
这有效。但是,这会将整个控件的背景设置为灰色,如何将所选项目的颜色更改为灰色?
I have a form with multiple drop downs... I would like to set the background color of the visible dropdowns to gray when they are disabled. All of these dropdown's id's begin with usrControl. Here is what I have this far..
$('select[id ^= "usrControl"]:visible').each(function(){
this.css("background-color")
});
Not sure how to get the disabled/enabled selectors.
Thanks in advance
Protected _picklistColorScriptText As String = "$(document).ready(function(){ " + _
"$('[id ^= ""usrControl""]:visible:disabled').css(""background-color"", '#DCDCDC'); " + _
"$('[id ^= ""usrControl""]:visible:enabled').css(""background-color"", '#FFFFFF');" + _
"});"
This works. However, this sets the background for the entire control to gray, how can I change the color of the selected item to gray?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 :disabled 伪选择器。另外你不需要 jQuery.each。只需针对返回的节点集进行操作即可。
这里的工作示例: http://jsfiddle.net/Cwm4W/
更新:响应下面OP的澄清,您可以只需选择包含的选项,如下所示:
此处的工作示例: http://jsfiddle.net/Cwm4W/1/
You can use the :disabled pseudo-selector. Plus you don't need jQuery.each. Just work against the returned nodeset.
Working example here: http://jsfiddle.net/Cwm4W/
UPDATE: Responding to OP's clarification below, you can simply select the contained option like so:
Working example here: http://jsfiddle.net/Cwm4W/1/
您仅获得 CSS 属性。
试试这个:
You are only getting the CSS property.
Try this:
我相信你正在寻找
I believe you are looking for