【问题标题】:How to handle multiple button in form? [duplicate]如何处理表单中的多个按钮? [复制]
【发布时间】:2018-07-30 15:40:45
【问题描述】:

在下面的表单中,当我们点击保存时,我们只会收到表单提交请求到服务器。

    <form id="form1" action="service1" method="POST">
     <button id="id1" onclick="getcount('emp')" >clickhere</button>

     <input id="save"  type="submit" class="btn-small btn-primary" value="Save" name="Save"/>

     </form>

但是当我们点击 clickhere 按钮时,我们会收到两个服务器请求。 即 1. 电话后服务1 2. getCount() 函数中的服务调用。

但我只需要 getCount() 函数服务调用。

我们如何处理上述情况?

【问题讨论】:

标签: javascript html


【解决方案1】:

将 type="button" 添加到进行 getcount() 调用的按钮,以便它覆盖默认的“提交”行为。

&lt;button id="id1" type="button" onclick="getcount('emp')" &gt;clickhere&lt;/button&gt;

【讨论】:

  • 谢谢!!它的工作!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-29
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 2012-08-28
  • 1970-01-01
  • 2015-01-17
相关资源
最近更新 更多