javascript <form> 标签中的 data-url 属性是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16722343/
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
what does data-url attribute in the <form> tag mean?
提问by Hai Lin
All,
全部,
Recently I found out some HTML source for a user registration, a form like below:
最近我发现了一些用于用户注册的 HTML 源代码,如下所示:
<form action="/users" class="signup-form" data-url="/users/current" id="new_user" method="post">
<input id="user_user_name" name="user[user_name]">
<input id="user_password" name="user[password]">
<input id="create-account-button" name="commit" type="submit" value="Create Account" />
</form>
My question is:
我的问题是:
1) what does data-url here mean? 2) why put input field name as user[user_name], user[password] this kind of format? Shouldn't make the input name just as 'user_name' and 'password' easier? I mean, this must relate to a data model user, so naming in this way will be better for server processing.
1) 这里的 data-url 是什么意思?2)为什么把输入字段名设为user[user_name],user[password]这种格式?不应该像“user_name”和“password”一样更容易输入名称吗?我的意思是,这必须与数据模型用户相关,因此以这种方式命名将更好地用于服务器处理。
Could anyone tell me if this is new HTML feature or jQuery feature? I did lots of search online, but I couldn't find out answer. Could you pelase give me any link or tutorial for this new html format submission?
谁能告诉我这是新的 HTML 功能还是 jQuery 功能?我在网上搜索了很多,但找不到答案。你能给我这个新的 html 格式提交的任何链接或教程吗?
Many thanks. Sam
非常感谢。山姆
回答by Daniel A. White
data-*
attributes are part of HTML5. They are up to the implementor's to decide on what they mean.the format of the
name
attributes is also arbitrary. its up to the framework on the server side to process it.
data-*
属性是 HTML5 的一部分。它们由实现者决定它们的含义。name
属性的格式也是任意的。它取决于服务器端的框架来处理它。
回答by eidsonator
It is a new in the HTML5 spec. It is a way to add custom attributes to your tags and have your docs still pass validation.
它是 HTML5 规范中的新内容。这是一种向标签添加自定义属性并使您的文档仍然通过验证的方法。
回答by Alnitak
Pages often include additional meta information intended to be processed by client side applications. This data has no special meaning other than what the application author wanted it to mean.
页面通常包括旨在由客户端应用程序处理的附加元信息。除了应用程序作者希望它的含义之外,此数据没有特殊含义。
In earlier versions of HTML, page authors would use arbitrary attribute names to pass these attributes. This would cause problems for page validators.
在早期版本的 HTML 中,页面作者会使用任意属性名称来传递这些属性。这会导致页面验证器出现问题。
In HTML5, W3C introduced data-XXX
attributes as a namespace to allow this data to be passed without risking it clashing with proper element attributes.
在 HTML5 中,W3C 引入了data-XXX
属性作为命名空间,以允许传递此数据,而不会冒与适当的元素属性发生冲突的风险。
Such values can (in compliant browsers) be accessed via the el.dataset
property.
这些值可以(在兼容的浏览器中)通过el.dataset
属性访问。
回答by Ligth
datacame with html5, that is used for when you need a custom html attribute.
数据随 html5 一起提供,用于需要自定义 html 属性时。
Example you need a attribute to hold the name of some persons, doing this is not valid:
例如,您需要一个属性来保存某些人的姓名,这样做是无效的:
<inpu type="text" name="carlos" id="whatever"/>.
But doing this, browser will acepte that attribute :D.
但是这样做,浏览器将接受该属性:D。
<input type="text" data-name="carlos" id="whatever"/>.
回答by lockedown
It looks like it might make things move faster on the page.
看起来它可能会使页面上的内容移动得更快。
Here is a link I found:
这是我找到的链接:
http://www.shawnmclean.com/blog/2011/02/how-can-html5-data-attributes-data-helps-efficiency/
http://www.shawnmclean.com/blog/2011/02/how-can-html5-data-attributes-data-helps-efficiency/