使用jquery更改类 [英] Change class using jquery

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

问题描述

我有follwoing名为rgExpandCol一流的TD和想改变它里面的类输入。下面是我的html:

 < TR>
    < TD类=rgExpandCol>
    <输入类=rgExpand...
    < / TD>
&所述; TR>

和我都试过这个jQuery,但我得到$发现是空:

  $(本).closest('TD')ATTR('rgExpand','rgCollapse')。

::

基本上我使用 radgrid控件和扩大其使用隐藏的行

$(本).closest('TR')下一个(TR),CSS('显示器','');

和$(这)是对电网的我的单击事件如此

  $(#<%= gv.ClientID%GT; TR:有(TD)),点击(函数(五){。


解决方案

使用removeClass移除()和addClass()来做出改变。

  $(#<%= gv.ClientID%GT; TR:有(TD)),点击(函数(五){。
    亦即preventDefault();
    $(本).find('输入')addClass('rgExpand')removeClass移除('rgCollapse')。
});

假设在选择使用的ID标识表。

I have a td with follwoing class named 'rgExpandCol' and want to change the class of input inside it. below is my html:

<tr>
    <td class="rgExpandCol">
    <input class="rgExpand" ...
    </td>
<tr>

and I have tried this jquery but I get $find is null:

$(this).closest('td').attr('rgExpand', 'rgCollapse');

EDIT :::

basically am using radgrid and expanding rows which are hidden using

$(this).closest('tr').next('tr').css('display', '');

and $(this) is on my click event of grid as so

$("#<%=gv.ClientID%> tr:has(td)").click(function (e) { 

解决方案

Use removeClass() and addClass() to make the change.

$("#<%=gv.ClientID%> tr:has(td)").click(function (e) {
    e.preventDefault();
    $(this).find('input').addClass('rgExpand').removeClass('rgCollapse');
});

Assuming that the id used in the selector identifies the table.

这篇关于使用jquery更改类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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