最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can we give attribute "name" to HTML <table>? - Stack Overflow

programmeradmin1浏览0评论

For the <form>, we can use a "name" like <form name="name">.

In the same way, can we add it to <table name="table1">?

For the <form>, we can use a "name" like <form name="name">.

In the same way, can we add it to <table name="table1">?

Share Improve this question edited Oct 4, 2021 at 19:10 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Dec 3, 2012 at 5:15 phaneeshphaneesh 1401 gold badge1 silver badge7 bronze badges 0
Add a comment  | 

5 Answers 5

Reset to default 11

name is not an allowed attribute of <table> in HTML5. From the fine specification:

Permitted attributes

global attributes & border

And if you look at the global attributes you won't find name in the list.

So you can't put a name attribute on a <table> and still have valid HTML. id however is a global attribute so you can use that instead of name (if of course your name is going to be unique within the page).

Try running this:

<!DOCTYPE html>
<head><title>t</title></head>
<body>
    <table name="pancakes"></table>
</body>

through http://validator.w3.org and you'll see that it doesn't like a name on <table>.

If you're still writing HTML4, you still can't put a name attribute on a <table>. From the fine specification:

<!ATTLIST TABLE                        -- table element --
  %attrs;                              -- %coreattrs, %i18n, %events --
  summary     %Text;         #IMPLIED  -- purpose/structure for speech output--
  width       %Length;       #IMPLIED  -- table width --
  border      %Pixels;       #IMPLIED  -- controls frame width around table --
  frame       %TFrame;       #IMPLIED  -- which parts of frame to render --
  rules       %TRules;       #IMPLIED  -- rulings between rows and cols --
  cellspacing %Length;       #IMPLIED  -- spacing between cells --
  cellpadding %Length;       #IMPLIED  -- spacing within cells --
  >

There's no name in that list and no name in coreattrs, i18n, or events either.

name is not allowed to table, instead of the this you can declare it in html5 trend

<table data-name="my_table"></table>

and use it in jquery for instance like that:

$('table [data-name=my_table]');

No dude, you cannot assign name to the table element.

For the table, you can give an id or a class attribute that refers a particular table in your HTML code and then based on it, you can then make changes to your table via CSS , javascript, jquery etc.

Hope this information helps.. !

name is a *standard attribute, and it can be placed on any element.

However, note that accessing elements by name is deprecated in favour of things like id and class. name should be reserved for form elements such as <input>.

Yes you can. e.g.

<table name="test" id="test">
<tr>
<td>..Your stuff..</td>
</tr>
</table>
发布评论

评论列表(0)

  1. 暂无评论