jQuery中HTML表单标签的有效/无效名称是什么? [英] What are valid / invalid names for HTML form tags in jQuery?

查看:114
本文介绍了jQuery中HTML表单标签的有效/无效名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这从我跑到这里的错误流出 jQuery $('form')。serialize()只返回一个序列化表单的一个元素,其中有一个名为elements的表单标签,如下所示:

 <形式> 
< input name =elements/>
< input name =e2/>
< / form>

阻止您使用jQuery的 $('form' ).serialize()(即你得到elements =,你应该得到elements =& e2 =)。

我想以获得关于表单标签的正确名称元素的更多一般信息。即什么是禁止标签(元素,名称等)以及名称的有效字符是什么。这些东西是在一个标准或参考手册中定义的,还是试验和错误?

想法和输入值得赞赏。

感谢您阅读。

解决方案

除了Jonathan Sampson所说的,您不应该使用用于表单对象的名称属性。 Mozilla开发人员中心列表,如果您愿意仔细看看包含一个对你来说很重要的元素属性,因为表单元素可以作为表单对象的直接属性访问。例如你的情况:

  form.elements; //与内置元素属性
form.e2相冲突;

所以请小心不要使用方法动作,它们也会与方法和动作 code>表单元素的属性。我希望你明白了。


This flows from the error I ran into here jQuery $(’form’).serialize() returns only one element of a form serialized where having a form tag named "elements", like so:

<form>
<input name="elements"/>
<input name="e2"/>
</form>

prevents you from accessing all the named elements of the form with jQuery's $('form').serialize() (i.e. you get "elements=" where you should get "elements=&e2=").

I'd like to have more general information about what proper "name" elements of form tags. I.e. what are the off-limits tags ("elements", "name", etc.), and what are the valid characters for a name. Are these things defined in a standard, or a reference manual, or is it trial and error?

Thoughts and input appreciated.

Thanks for reading.

解决方案

Beside what Jonathan Sampson said you should not use names that are used for form objects properties. There is a list on Mozilla Developer Center, which if you'll look carefully contains an elements property important for you because form elements may be accessed as direct attributes of the form object. For example in your case:

form.elements; // collides with the built-in elements property
form.e2;

So be careful not to use names like method, or action which will also collide with the value of the method and action attributes of the form element. I hope you got the idea.

这篇关于jQuery中HTML表单标签的有效/无效名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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