Javascript 我们可以给 html <table> 命名吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13677536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can we give name to html <table>?
提问by phaneesh
For the <form>we can give name like <form name="name">.
对于<form>我们可以命名为<form name="name">.
In the same way can we give it to <table name="table1">
以同样的方式,我们可以把它给 <table name="table1">
回答by mu is too short
nameis not an allowed attribute of <table>in HTML5. From the fine specification:
name不是<table>HTML5 中允许的属性。从精细规格:
Permitted attributes
global attributes& border
允许的属性
全局属性和边框
And if you look at the global attributesyou won't find namein the list.
如果您查看列表中找不到的全局属性name。
So you can't put a nameattribute on a <table>and still have valid HTML. idhowever 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).
因此,您不能将name属性放在 a 上<table>并且仍然具有有效的 HTML。id然而是一个全局属性,因此您可以使用它来代替name(当然,如果您的名字在页面中是唯一的)。
Try running this:
尝试运行这个:
<!DOCTYPE html>
<head><title>t</title></head>
<body>
<table name="pancakes"></table>
</body>
through http://validator.w3.organd you'll see that it doesn't like a nameon <table>.
通过http://validator.w3.org,你会看到它不喜欢nameon <table>。
If you're still writing HTML4, you still can't put a nameattribute on a <table>. From the fine specification:
如果您仍在编写 HTML4,您仍然无法将name属性放在<table>. 从精细规格:
<!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 namein that list and no name in coreattrs, i18n, or eventseither.
有没有name在该列表中,并没有名字coreattrs,i18n或events任一。
回答by Waqar Alamgir
name is not allowed to table, instead of the this you can declare it in html5trend
name 不允许表,而不是 this 你可以在html5趋势中声明它
<table data-name="my_table"></table>
and use it in jquery for instance like that:
并在 jquery 中使用它,例如:
$('table [data-name=my_table]');
回答by Neville
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.
对于表格,您可以在 HTML 代码中提供一个 id 或一个类属性来引用特定的表格,然后基于它,您可以通过 CSS、javascript、jquery 等对您的表格进行更改。
Hope this information helps.. !
希望这些信息有帮助..!
回答by Niet the Dark Absol
nameis a Standard Attribute, it can be placed on any element.
name是一个标准属性,它可以放在任何元素上。
However note that accessing elements by nameis deprecated in favour of things like idand class. nameshould be reserved for form elements such as <input>.
但是请注意,name不推荐使用by 访问元素,而使用idand之类的东西class。name应保留用于表单元素,例如<input>.
回答by Rashmi Nagaraja
Yes you can. e.g.
是的你可以。例如
<table name="test" id="test">
<tr>
<td>..Your stuff..</td>
</tr>
</table>

