Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...