这是什么:document.reservation.submit();应该做的? [英] What is this : document.reservation.submit(); supposed to do?

查看:55
本文介绍了这是什么:document.reservation.submit();应该做的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用旧开发人员的代码进行工作,并且正在尝试填写保留表格.

I am reworking on a code of an old developer and I'm trying to do a form for reservation.

我查看了整个代码,唯一被称为保留的是表单的名称和ID.

I've looked across the whole code the only thing called reservation is the name and the id of the form.

具有时尚风格的表:display:none ...

Form who's is in style : display:none ...

那么有两个问题:首先,到底该怎么做

So two question in one : First of all what the heck is supposed to do

document.reservation.submit();是否应该以他的名字获取表格?

document.reservation.submit(); Is it suppose to get the form by his name ?

不是像document.getElementById('reservation').submit()这样的东西吗?

我的第二个问题是:如果将所有值都设置为display:none,我将如何发送表单,我坚信它无法工作,如果要隐藏它们,则应使用隐藏属性...

And my second question is : How the form can be sent if all the value are set to display:none I tough it couldn't work and if you want to hide them you shall use hidden property...

我需要一些帮助,伙计们:)

I need a bit of help on this guys pls :)

<form name='reservation' action='http://xxxx/reservationFormAction.to' method="POST" id="reservation">
    <input type="hidden" id="productLive" name="product" value="{$product.info.code}"/>
    <input type="hidden" name="complementaryParameters" value=""/>    
    <input type="text" name="depCityCode" id="depCityCode" style="display:none"  />
    <input type="text" name="dateDep" id="dateDep" style="display:none" />
    <input type="text" name="nightDuration" id="nightDuration"  style="display:none" />
    <input type="text" name="dayDuration" id="dayDuration"  style="display:none" />
    <input type="text" name="provider" value="{$product.tourOperator.code}" style="display:none" />
    <input type="text" id="toProduct" name="toCode" value="{$product.info.toProductCode}" style="display:none" />
    <input type="text" name="catalogCode" value="{$product.info.code}" style="display:none" />
    {if $ecall}
    <input type="text" name="reservationProfileChannelCode" value="ECALL" style="display:none" />
    {else}
    <input type="text" name="reservationProfileChannelCode" value="ADV" style="display:none" />
    {/if}
    <input type="text" name="nbAdults" id="nbAdults" style="display:none" />
    <input type="text" name="nbChildren" id="nbChildren" style="display:none" />
    <input type="text" name="nbBabies" id="nbBabies" style="display:none" />
    <input type="text" name="productUrl" id="productUrl" style="display:none" value="http://www.xxxx.com/{$product.slug}_{$product.info.code}.html" />
    <input type="text" name="homeUrl" id="homeUrl" style="display:none" value="http://www.xxxx.com" />
    <span id="ageChild" style="display:none"></span>
<div class="update-search clearfix">

推荐答案

document.reservation使用name reservation获取表单的HTMLFormElement.然后调用submit提交表单(不触发submit事件).

document.reservation gets the HTMLFormElement for the form with the name reservation. Then calling submit submits the form (without triggering the submit event).

那为什么不document.getElementById呢? 也可以起作用,但是document.reservation可以起作用,因为document对象自动获得了在其上创建的各种属性,包括通过其name引用表单的属性. HTML5规范的第3.1.3节对此进行了介绍 *(您必须向下滚动一点):

So why not document.getElementById? That would also work, but document.reservation works because the document object gets various properties created on it automagically, including properties referring to forms by their name. This is covered in §3.1.3 of the HTML5 spec *(you have to scroll down a fair bit):

Document接口支持命名属性.随时支持的属性名称包括所有appletembedformiframeimg和暴露的object元素中所有appletname内容属性的值.具有非空name内容属性的Document以及Document中具有非空id内容的所有applet和暴露的object元素的id内容属性的值属性,以及Document中所有具有非空name内容属性和非空id内容属性的所有img元素的id内容属性的值.

The Document interface supports named properties. The supported property names at any moment consist of the values of the name content attributes of all the applet, exposed embed, form, iframe, img, and exposed object elements in the Document that have non-empty name content attributes, and the values of the id content attributes of all the applet and exposed object elements in the Document that have non-empty id content attributes, and the values of the id content attributes of all the img elements in the Document that have both non-empty name content attributes and non-empty id content attributes.

这些属性的值是nameid来自的元素.

The value of those properties is the element the name or id came from.

window对象还获取带有id的每个元素的属性,如在此进行了描述:

The window object also gets properties for every element with an id, as described here:

任何时候,受支持的属性名称都以树顺序包括以下内容,而忽略了以后的重复项:

The supported property names at any moment consist of the following, in tree order, ignoring later duplicates:

  • 名称不是空字符串的活动文档的任何子级浏览上下文的浏览上下文名称,
  • 活动对象中所有aappletareaembedformframesetimgobject元素的name内容属性的值具有非空name内容属性的文档,并且
  • 活动文档中具有非空id内容属性的任何HTML元素的id内容属性的值.
  • the browsing context name of any child browsing context of the active document whose name is not the empty string,
  • the value of the name content attribute for all a, applet, area, embed, form, frameset, img, and object elements in the active document that have a non-empty name content attribute, and
  • the value of the id content attribute of any HTML element in the active document with a non-empty id content attribute.

这些属性的值还是nameid的元素.

Where again the value of those properties is the element the name or id came from.

在这两种情况下,这都是HTML5规范,该规范对大多数浏览器以前广泛使用但非标准的做法进行了标准化,并在野外的页面上得到了广泛使用.

In both cases, this is the HTML5 specification standardizing the previously-widespread-but-nonstandard practice most browsers had, which is widely used on pages in the wild.

如果所有值都设置为显示,则如何发送表单:没有,我不敢说它无法工作,如果要隐藏它们,则应使用hidden属性...

How the form can be sent if all the value are set to display:none I tough it couldn't work and if you want to hide them you shall use hidden property...

每个问题最好问一个问题.

It's best to ask one question per question.

CSS display属性对是否提交表单字段完全没有影响;您可能正在考虑该字段的 disabled状态:禁用的表单字段确实在提交时被排除在表单之外.

The CSS display property has no effect at all on whether form fields are submitted; you're probably thinking of the field's disabled state: Disabled form fields are indeed left out of the form on submission.

这篇关于这是什么:document.reservation.submit();应该做的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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