jQuery正文问题-ASP.NET [英] JQuery tbody question - ASP.NET

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

问题描述

我有一个aspx页面,看起来像这样:

I have a aspx page that looks something like this:

<table runat="server" id="tblTEst">
  <tr id="trHeader" runat="server">

  </tr>
  <tr id="trRow1" runat="server">

  </tr>
  <tr id="trRow2" runat="server">

  </tr>
</table>

当我写我的JQuery说获得s的计数时,我需要这样做:

When I write my JQuery to say get a count of s, I need to do:

alert($('#' + strTableId).children('tbody').children('tr').length);

我的问题是,何时添加TBODY?当我做一个InnerHTML时,我看到了TBODY.我想知道这是否是ASP.NET要做的事情?

My question is when does the TBODY get added? When I do a InnerHTML, I do see the TBODY. I was wondering if this is something ASP.NET does?

编辑 感谢您的回答.如果它是由浏览器添加的,我是否需要担心在多个浏览器中测试代码以确保JQuery的兼容性?我的印象是,JQuery与所有浏览器兼容,而我不必担心在不同的浏览器上测试代码.

EDIT Thanks for the answers. If it's added by the browser, do I need to worry about testing the code in multiple browsers to ensure compatibility of JQuery? I was under the impression, JQuery is compatible with all browsers and I would'nt have to worry about testing the code on different browsers.

推荐答案

浏览器会执行此操作,这是在构建DOM时清理HTML的过程的一部分. 标准指定必须出现TR元素在TBODY,THEAD或TFOOT元素中,并且由于您均未指定任何内容,因此浏览器会为您添加一个来帮助您.

It's something the browsers do, as part of the process of cleaning up the HTML while building the DOM. The standard specifies that TR elements must occur within a TBODY, THEAD, or TFOOT element, and since you specified none of those, the browser helps you out by adding one for you.

如果您想忽略这一点,可以将表达式重写为:

If you wish to ignore this, you can re-write your expression as:

alert($('#' + strTableId).find('tr').length);

...但是,最好将行显式包装在TBODY中,以免将来造成混乱.

...But, you would do well to explicitly wrap your rows in TBODY so as to avoid confusion in the future.

这篇关于jQuery正文问题-ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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