当表格提交中的类相同时,按钮和跨度之间有什么区别。

时间:2022-01-25 16:36:05

i have overcome with span and button issue while submitting the form with ajax call.

我在使用ajax调用提交表单时克服了跨度和按钮问题。

Here is my code with button:

这是我的代码与按钮:

<form>
<button class="btn btn-round btn-fill pull-right mg-top"  id="gdBasic" >Generate</button>
</form>

Here is my code with span:

这是我的代码span:

<form>
<span class="btn btn-round btn-fill pull-right mg-top"  id="gdBasic" >Generate</span>
</form>

javascript Generate Starts here.....

javascript生成启动这里.....

$("#gdBasic").click(function () {
///////////////Ajax call is inside.//////////////////
});

My problem is with tag span the form is submitting well and getting response from ajax but where as when i did it with button tag page is refreshing.

我的问题是标签跨度表单正在提交并从ajax得到响应但是当我用按钮标签页面做的时候是令人耳目一新的。

So i just want to know what is the difference between them i have not written <button type='submit'> for button tag

所以我只是想知道它们之间有什么区别我没有为按钮标签写

2 个解决方案

#1


6  

Browsers often interpret buttons within forms as submit buttons if you do not tell them otherwise. If you need them to stop doing this, use:

如果你没有告诉他们,浏览器通常会将表单中的按钮解释为提交按钮。如果您需要它们停止这样做,请使用:

// with type button, the form will not refresh the page.
<button type="button">Will not refresh the page.</button>

If you know you are always submitting your form via ajax (for example, if you are doing complex validations first), you can add this as a safety on the form:

如果您知道自己总是通过ajax提交表单(例如,如果您先进行复杂的验证),则可以在表单上添加以下内容:

<form onsubmit="return false;">

That will prevent any default submissions from the html, but still allow you to manipulate the form inputs and use them in ajax calls.

这将阻止来自html的任何默认提交,但仍允许您操纵表单输入并在ajax调用中使用它们。

#2


2  

span is a inline page element, a container for stuff which by default wraps around its content unless otherwise specified. button is a control which is designed to provide an event on page which generally gets some action done like submitting form fields, adding new stuff to page, causing page components to re-arrange. etc. Globally, web users identify with visual representation of span as content display and visual representation of button as action enabler.

span是一个内联页面元素,一个容器,用于默认情况下包装其内容的东西,除非另有说明。按钮是一个控件,旨在提供页面上的事件,通常会执行一些操作,如提交表单字段,向页面添加新内容,导致页面组件重新排列。在全球范围内,网络用户将跨度的可视化表示识别为内容显示和按钮的可视表示作为动作使能者。

If form submit is your intention and you do not want to use <input type="submit">, use <input type="button"> or as specified in answer above <button type="button">

如果表单提交是您的意图并且您不想使用,请使用或在上面的回答中指定

#1


6  

Browsers often interpret buttons within forms as submit buttons if you do not tell them otherwise. If you need them to stop doing this, use:

如果你没有告诉他们,浏览器通常会将表单中的按钮解释为提交按钮。如果您需要它们停止这样做,请使用:

// with type button, the form will not refresh the page.
<button type="button">Will not refresh the page.</button>

If you know you are always submitting your form via ajax (for example, if you are doing complex validations first), you can add this as a safety on the form:

如果您知道自己总是通过ajax提交表单(例如,如果您先进行复杂的验证),则可以在表单上添加以下内容:

<form onsubmit="return false;">

That will prevent any default submissions from the html, but still allow you to manipulate the form inputs and use them in ajax calls.

这将阻止来自html的任何默认提交,但仍允许您操纵表单输入并在ajax调用中使用它们。

#2


2  

span is a inline page element, a container for stuff which by default wraps around its content unless otherwise specified. button is a control which is designed to provide an event on page which generally gets some action done like submitting form fields, adding new stuff to page, causing page components to re-arrange. etc. Globally, web users identify with visual representation of span as content display and visual representation of button as action enabler.

span是一个内联页面元素,一个容器,用于默认情况下包装其内容的东西,除非另有说明。按钮是一个控件,旨在提供页面上的事件,通常会执行一些操作,如提交表单字段,向页面添加新内容,导致页面组件重新排列。在全球范围内,网络用户将跨度的可视化表示识别为内容显示和按钮的可视表示作为动作使能者。

If form submit is your intention and you do not want to use <input type="submit">, use <input type="button"> or as specified in answer above <button type="button">

如果表单提交是您的意图并且您不想使用,请使用或在上面的回答中指定