如何使用jQuery添加CSS类? [英] How to add css class using jQuery?

查看:67
本文介绍了如何使用jQuery添加CSS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了此脚本来查找控件,然后向其添加css类

I have written this script to find control and then add css class to it

var abc = $(this).parent().parent().parent().attr(''id'');


它工作正常.当我在警报中测试变量时,如


It works fine. When I test variable in alert like

alert(abc);


然后显示正确的控件ID.现在,我想向该控件添加css类.我尝试了此代码,但无法正常工作.


then it display correct id of the control. Now I want to add css class to this control. I tried this code but not working.

$(''#abc'').addClass(''abc'')

推荐答案

(this).parent().parent().parent().attr(''id'');
(this).parent().parent().parent().attr(''id'');


它工作正常.当我在警报中测试变量时,如


It works fine. When I test variable in alert like

alert(abc);


然后显示正确的控件ID.现在,我想向该控件添加css类.我尝试了此代码,但无法正常工作.


then it display correct id of the control. Now I want to add css class to this control. I tried this code but not working.


(''#abc'').addClass(''abc'')
(''#abc'').addClass(''abc'')


请确保您在.addClass方法中添加的"abc"是可用于页面的有效css类.如果是这样,那么它将起作用.如果没有看到该类尝试应用的所有替代,则可能还有其他CSS问题,但前提是您的
Make sure that the ''abc'' that you add in the .addClass method is a valid css class that is available to the page. If it is, then it will work. If you don''t see all the overrides that the class tries to apply, then you may have other css issues, but as long as your


这篇关于如何使用jQuery添加CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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