小编JJB*_*ter的帖子

有没有快速通过jQuery删除表行的方法

我有一个50个奇数行,11列的表格.每一行都有一个独特的id组成部分id="row_<clientid>_rownumber".第二列中有一个复选框id="group_<clientid>_<petid>_rownumber"

编辑截图http://www.forsythesit.com.au/res/img/slowrowremoval.jpg

当用户单击复选框时,我想删除除属于所选客户端的所有行.我的代码工作如下:

var sClient = $(this).attr("id").substring(6); // trim off group_
sClient = sClient.substring(0,sClient.indexOf("_")); // trim off anything after clientid
$("tr[id^=row_]").not("tr[id^=row_" + sClient + "]").remove(); 
Run Code Online (Sandbox Code Playgroud)

问题是需要很长时间才能在IE中得到"脚本耗时太长"的警告.

是否有更快的方法来删除许多行?

顺便说一句:使用jQuery 1.4.3需要4.4秒,使用jQuery 1.4.2需要1.3秒

问题解决了所有人.最终提示由@VisusZhao提供.这是最终的工作片段:

var KeepRows = $("#bookingstable tbody tr[id^=row_" + sClient + "_]");
$("#bookingstable tbody").empty();
$("#bookingstable tbody").append(KeepRows);
Run Code Online (Sandbox Code Playgroud)

谢谢你们

performance jquery internet-explorer

5
推荐指数
1
解决办法
1269
查看次数

我的记录集关闭后是否必须处理SqlCommand?

好吧,这是微不足道的,但它一直困扰着我.我有这样的代码

oCmd = new SqlCommand("getBooking", oCon); 
oCmd.CommandType = CommandType.StoredProcedure;
oRs = oCmd.ExecuteReader();
do while (oRs.Read()) {
    // do stuff
}
oRs.Close();
oCmd.Dispose();
Run Code Online (Sandbox Code Playgroud)

但是我Dispose可以在ExecuteReader这之后移动到:

oCmd = new SqlCommand("getBooking", oCon); 
oCmd.CommandType = CommandType.StoredProcedure;
oRs = oCmd.ExecuteReader();
oCmd.Dispose();
do while (oRs.Read()) {
    // do stuff
}
oRs.Close();
Run Code Online (Sandbox Code Playgroud)

我试过了,它有效,但感觉就像我在调皮.这种方法有问题吗?我问,因为经常需要重新使用其中的SqlCommand对象do while,而不是我不想创建多个SqlCommand对象.

c# asp.net dispose sqlcommand

1
推荐指数
1
解决办法
1414
查看次数