English 中文(简体)
Jquery 隐藏表格单元格内容
原标题:Jquery to hide table cell contents

我有一个像这样布置的桌子:

<table>
  <tr>
    <td>checkbox</td>
    <td>text-text-text</td>
    <td>dropdownlist</td>
    <td>textbox</td>
  </tr>
</table>

我正在尝试根据复选框的勾选状态来切换下拉列表和文本框的可见性。我已经设置了正确的单击事件,但它在加载新数据时不会持久化行的可见性。我该如何在Jquery中实现这一点?

编辑:这是连接到复选框点击事件的函数。 它正确地切换元素的可见性。我遇到的问题是获取从数据库中加载的新行以正确的可见性开始。(我在asp.net中使用重复器控件来构建表,因此将客户端ID传递到函数中)。

我有一个带有每行第一个单元格中的复选框的表格,我要使用jquery中的哪个选择器来获取该行其余单元格的内容,从复选框开始。

 function ToggleVisibility(position, hometown, state, checkbox, name, license) {
        if ($("#" + checkbox)[0].checked) {
            $("#" + position).css( visibility ,  visible ).fadeIn( slow );
            $("#" + hometown).css( visibility ,  visible ).fadeIn( slow );
            $("#" + state).css( visibility ,  visible ).fadeIn( slow );
            $("#" + name).css( font-weight ,  bold );
            $("#" + license).css( font-weight ,  bold );
        }
        else {
            $("#" + position).css( visibility ,  hidden ).fadeOut( slow );
            $("#" + hometown).css( visibility ,  hidden ).fadeOut( slow );
            $("#" + state).css( visibility ,  hidden ).fadeOut( slow );
            $("#" + name).css( font-weight ,  normal );
            $("#" + license).css( font-weight ,  normal );
        }
}
问题回答

唯一的方法是使用Ajax将更新的状态持久化到服务器。例如:

<input type="checkbox" id="cb1" class="save">

和:

$(":checkbox.save").click(function() {
  $.post( /save.php , {id: this.id, checked: this.checked});
  $("rowid").toggle(this.checked);
});

当服务器呈现页面时,它可以查询持久化的页面状态并正确呈现控件和行。

You may want to have a look at livequery, which is a plugin for jquery: Livequery

用你想要藏匿的物品藏在一张DIV中,并隐藏着DIV,而不是桌子。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签