jQuery addClass不起作用 [英] jQuery addClass not working

查看:159
本文介绍了jQuery addClass不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用addClass在我的Joomla模板上给我斑马条纹的表.我正在使用以下代码:

I'm trying to use addClass to give me zebra-striped tables on my Joomla template. Im using the following code:

 <script>
  jQuery(function($) {
    $("tr:odd").addClass("odd");
  });
</script>

我已经能够使用tr:odd选择器将css动态添加到表行中,但是当我使用addClass函数时,它只是没有(我检查了产生的源代码,并且表行都没有类奇数").

I've been able to use the tr:odd selector to add css to table rows dynamically, but when i use the addClass function it just doesnt (I checked the source code produced and none of the table rows have the class "odd").

不知道我可能做错了什么,不胜感激.

Havn't a clue what I could be doing wrong, would appreciate any help.

推荐答案

您知道,当您查看源代码时,使用Javascript对DOM所做的更改不会反映出来.

So you know, changes to the DOM with Javascript are not reflected when you view the source.

如果您的CSS看起来像这样,那么该代码应该可以工作...

That code should work if your CSS looks like this...

tr.odd td
{
    background:#070;
}

这篇关于jQuery addClass不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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