这段代码中定义的表单的“submit()”函数在哪里?

发布于 2024-10-26 00:14:01 字数 2384 浏览 3 评论 0原文

我正在从已经创建的网页(php,javascript和smarty)中学习,我保证我一直在努力理解这段代码,但我的头脑就是不能,我不知道它是如何工作的,我已经读了又读了,但我还是不明白。 下一个代码完美地工作,但我不知道如何。这是关于联系表格的。 这是原始的 php 页面:

<?php
include("includes/globals.php");
include("includes/smarty/Smarty.class.php"); 
$vista = new Smarty();
$vista->display('contacto.tpl');
?>

如您所见,它只显示 contacto.tpl,即(我将只放置有趣的部分):

<link href="{$smarty.const.__SERVER_URL__}css/estilo.css" rel="stylesheet" type="text/css" />
<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
<link href="../css/coeco.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{$smarty.const.__SERVER_URL__}scripts/jquery.js"></script>

{literal}
<script>
    function validar()
    {
    $('#formContacto').submit();
}
</script>
{/literal}
</head>
<body>
  <form id="formContacto" action="/contacto-enviado.html" method="post">
    <table class="formulario_contacto" cellspacing="0" cellpadding="0">
      <tr>
        <td width="228" height="17">NOMBRE</td>
        <td width="110" height="17">TEL&Eacute;FONO</td>
        <td height="17">E-MAIL</td>
      </tr>
      <tr>
        <td><input class="campo_texto" name="nombre" id="nombre" type="text" /></td>
        <td><input class="campo_texto2" name="telefono" type="text" /></td>
        <td><input class="campo_texto" name="email" id="email" type="text" /></td>
      </tr>
    </table>
    <table class="formulario_contacto" cellspacing="0" cellpadding="0">
      <tr>
        <td height="17">SU MENSAJE</td>
      </tr>
      <tr>
        <td><textarea class="texto_contacto" name="detalles" rows=5></textarea>
          <div align="right"><a class="btn_formulario_contacto2" href="#" onclick="validar()">enviar</a></div></td>
      </tr>
    </table>
  </form>
  {include file="foot.tpl"} </div>
</body>
</html>

所以,好吧,好吧,它从表单获取数据并使用函数submit(),但是函数submit()在哪里定义的呢?我的意思是,是的,我已经阅读了 http://api.jquery.com/submit/ 并且它是一种触发器,但它必须在某个地方定义,对吧?在哪里?这段代码怎么可能工作? 谢谢! 抱歉,我知道我很笨。

I am learning from already created webpages (php,javascript, and with smarty) and I promise I've been trying hard to understand this code but my mind just can't, I don't how it works, I have read and read, but I still don't understand.
The next code works perfectly, but I don't know how. It's about a contact form.
This is the original php page:

<?php
include("includes/globals.php");
include("includes/smarty/Smarty.class.php"); 
$vista = new Smarty();
$vista->display('contacto.tpl');
?>

As you can see, it just displays contacto.tpl, which is (I will put just the interesting parts):

<link href="{$smarty.const.__SERVER_URL__}css/estilo.css" rel="stylesheet" type="text/css" />
<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
<link href="../css/coeco.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{$smarty.const.__SERVER_URL__}scripts/jquery.js"></script>

{literal}
<script>
    function validar()
    {
    $('#formContacto').submit();
}
</script>
{/literal}
</head>
<body>
  <form id="formContacto" action="/contacto-enviado.html" method="post">
    <table class="formulario_contacto" cellspacing="0" cellpadding="0">
      <tr>
        <td width="228" height="17">NOMBRE</td>
        <td width="110" height="17">TELÉFONO</td>
        <td height="17">E-MAIL</td>
      </tr>
      <tr>
        <td><input class="campo_texto" name="nombre" id="nombre" type="text" /></td>
        <td><input class="campo_texto2" name="telefono" type="text" /></td>
        <td><input class="campo_texto" name="email" id="email" type="text" /></td>
      </tr>
    </table>
    <table class="formulario_contacto" cellspacing="0" cellpadding="0">
      <tr>
        <td height="17">SU MENSAJE</td>
      </tr>
      <tr>
        <td><textarea class="texto_contacto" name="detalles" rows=5></textarea>
          <div align="right"><a class="btn_formulario_contacto2" href="#" onclick="validar()">enviar</a></div></td>
      </tr>
    </table>
  </form>
  {include file="foot.tpl"} </div>
</body>
</html>

So, well, ok, fine, it gets data from a form and it submits it with the function submit(), but where is function submit() defined? I mean, yes, I've read http://api.jquery.com/submit/ and it's kind of a trigger, but it must be defined somewhere, right? where? how is it possible that this code works?
Thanks!
Sorry, I know I'm so neeeeeeewbie.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

执着的年纪 2024-11-02 00:14:02

Submit() 方法是在“form”DOM 元素上定义的。 jQuery 只是调用该方法来提交页面上的表单。

The submit() method is defined on the "form" DOM element. jQuery is just calling into that method to submit the form on the page.

神魇的王 2024-11-02 00:14:02

jQuery 使用的提交函数位于 jQuery 代码本身内部。您正在使用“智能”模板引擎通过这一行将 jQuery 包含在您的页面中。

<script type="text/javascript" src="{$smarty.const.__SERVER_URL__}scripts/jquery.js"></script>

完成此操作后,您现在可以访问 jQuery 提供的所有强大功能,例如 submit()< /code> 提交表单的函数。 jQuery 的版本有助于使您的提交工作跨浏览器。如果您想了解有关提交功能的更多信息,请查看此处

The submit function that jQuery is using is inside of the jQuery code itself. You're using the 'smarty' templating engine to include jQuery in your page with this line

<script type="text/javascript" src="{$smarty.const.__SERVER_URL__}scripts/jquery.js"></script>

Once you've done that, you now have access to all of the awesomeness that jQuery provides, such as, the submit() function to submit a form. jQuery's version helps to make your submit work cross browser. If you'd like to see more on the submit function, look here.

尝蛊 2024-11-02 00:14:02

7年后的未来就是你。

没有人正确回答你的问题。所以我会尽力而为。

是一个 HTML 对象,具有一些特殊属性,可将其与其他 HTML 元素区分开来,就像

特别是,

允许将信息发送到服务器。信息通过 HTTP 请求发送,使用的方法在属性 method 中定义(GETPOST),而作为 URL请求的发送位置在属性 action 中指定。

的工作方式与任何其他 HTML 对象相同,通过标准进行管理和指定。负责它的官方机构是 W3C,以下是表单规范:
https://www.w3.org/TR/html52/sec-forms。然后

,浏览器可以自由地实现该规范,因此定义行为的“位置”细节位于浏览器核心的内部。例如,如果您足够深入地研究 Chromium 项目(Chrome 所基于的核心),您可能会找到一个实现。然而,了解规格足以使用它。

回到您的具体示例:

此表单将从出现此表单的客户端页面创建并发送 POST 请求,并将表单中输入的信息发送到相对 URL /contacto-enviado.html

进一步阅读

有关一般工作原理的详细解释,请检查:
https://developer.mozilla.org/en-US/文档/学习/HTML/Forms/Sending_and_retrieve_form_data

it's you in the future, 7 years later.

Nobody answered your question properly. So I'll do my best.

A <form> is an HTML object with some special properties that differentiate it from other HTML elements, the same way a <button> or a link <a> have special properties that differentiate them from others.

In particular, <form> allows to send information to a server. The information is sent through an HTTP request, the method used is defined in the property method (either GET or POST), while as the URL where the request is sent is specified in the property action.

The way <form> works is governed and specified the same way any other HTML objects are, via a standard. The official body in charge of it is W3C, here is the spec for forms:
https://www.w3.org/TR/html52/sec-forms.html

The spec is then freely implemented by browsers, so the specifics of 'where' the behaviour is defined is inside the guts of the browser core. For instance, you might find an implementation if you look deep enough in the Chromium Project, which is the core in which Chrome is based on. However knowing the specs is more than enough to work with it.

Going back to your specific example:

This form will create and send a POST request from the client page where this form appears with the information input in the form to the relative URL /contacto-enviado.html

Further Reading

For a nice explanation of how works in general, check:
https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data

爱冒险 2024-11-02 00:14:02

正如您所说,submitonSubmit 事件的触发器。因此,当它被调用时,它只会使表单调用表单上的该事件...默认情况下,它将执行与单击表单中的submit 输入完全相同的操作。

Like you said submit is a trigger for the onSubmit event. So when its called it just makes the form invokes that event on the form... by default it will do the exact same thing as clicking a submit input within the form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文