【问题标题】:Input name submit not submit the form输入姓名提交不提交表单
【发布时间】:2016-04-20 05:21:58
【问题描述】:

如果我将按钮命名为“提交”,则表单不会提交。但是,如果我更改了名称,则表单正在提交。

HTML 代码:

<form name="my_form" action="/search" method="get" id="my_form">
/** code **/
<button name="submit" type="submit"><i class="fa fa-angle-right"></i></button>
</form>

如果我更改 button 其他名称,它将起作用并提交表单。

JQUERY 代码

$( document ).ready(function() {
    $('.attr_list').on('ifChanged', function(event){
        alert("message will display"); // here alert will come but form is not submitting
        $("#my_form").submit();
    });
});

如果我将按钮命名为“提交”,为什么它不提交?

【问题讨论】:

  • $('.attr_list').on('ifChanged', function(event){attr_list相关的代码在哪里。请发布您的完整代码
  • 请附上完整的代码,特别是.attr_list是怎么来的。
  • .attr_list 没关系。如果我在 $('.attr_list').on('ifChanged', function(event) 上发出任何警报,它会显示警报消息。但表单没有提交

标签: php html


【解决方案1】:

我认为您应该将按钮名称从“提交”更改为其他任何名称。

原因:

表单元素有一个名为submit 的属性,您可以调用该函数来提交它们。 (当您在 jQuery 实例上调用 submit 时,jQuery 会在后台使用它。)但是 Form 元素也会使用字段名称接收表单中每个字段的属性,因此如果您有一个名为“submit”的字段,它会覆盖submit 函数,这意味着您不能以编程方式提交表单。

您的代码应该是:

<form name="my_form" action="/search" method="get" id="my_form">
/** code **/
<button name="othername" type="submit"><i class="fa fa-angle-right"></i></button>
</form>

它会起作用的......

【讨论】:

    【解决方案2】:

    你也可以试试:

    $("form").submit(function(){
         alert("Submitted");
    });
    

    而不是 $("#my_form").submit(); 如果它正在制造问题

    【讨论】:

      【解决方案3】:

      您的文件中是否有任何可用的 ob_start()。请删除它并尝试一次。

      【讨论】:

      • 与问题中使用标签“php”相反,这个问题不涉及任何PHP,听起来HTML没有正确显示(这就是@987654321 @ 应该会这样做)。
      • 这不是答案,应该是评论。其中的问题应该有一个问号,而不是一个点,好像它只是一个句子。
      猜你喜欢
      • 2016-03-14
      • 2016-12-04
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2015-08-13
      相关资源
      最近更新 更多