php - 这段代码中定义的表单的 `submit()` 函数在哪里?

标签 php javascript forms submit smarty

我正在从已经创建的网页(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/它是一种触发器,但它必须在某个地方定义,对吗?在哪里?这段代码怎么可能工作? 谢谢! 抱歉,我知道我很neeeeeeeewbie。

最佳答案

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

关于php - 这段代码中定义的表单的 `submit()` 函数在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5427731/

相关文章:

php - Libreoffice --headless 拒绝转换,除非 root,无法从 PHP 脚本运行

php - 为什么我不能将零设置为数组中的第一个键?

javascript - 在 v-text-field 或 v-textarea vuetify Vue.js 中显示实时建议词

javascript - 通过另一个变量名访问对象的数据

html - 获取 HTML 选择下拉列表以在移动设备上呈现

PHP PDO 总是只给出一个结果

javascript - 使用 Lodash 复制除一个字段外的所有字段,而不使用 Object.assign()

jquery - 使用 html5 的 placeholder 属性时如何防止默认焦点在文本字段上

javascript - AngularJS ng-repeat 具有多个显示不同值的列表

php - 使用 URL 字符串插入 MySQL