Html 表单内部的图像按钮,don';我不想屈服
我有一个表单,里面有一个图像按钮,这个图像按钮正在提交表单。如何覆盖此功能Html 表单内部的图像按钮,don';我不想屈服,html,forms,button,submit,Html,Forms,Button,Submit,我有一个表单,里面有一个图像按钮,这个图像按钮正在提交表单。如何覆盖此功能 <form><input type="image" src="/images/arrow.png" id="imageButton" onClick="javascript:autofill();"/></form> 为什么不直接使用图像?return false还将停止表单提交操作 <form><input type="image" src="/images/ar
<form><input type="image" src="/images/arrow.png" id="imageButton" onClick="javascript:autofill();"/></form>
为什么不直接使用图像?return false还将停止表单提交操作
<form><input type="image" src="/images/arrow.png" id="imageButton" onClick="autofill();return false;"/></form>
只需在autofill()函数后返回false即可
onclick="autofill();return false;"
为什么要使用输入元素呢?如果您不想导致任何提交或重置行为,我认为仅使用带有onclick事件的图像更合适
<image src="/images/arrow.png" onclick="javascript:autofill();" width="xxx" height="xxx" alt="Autofill" />
尝试使用事件。preventDefault在单击按钮时中止提交事件 例如:
$("#idButton").click(function(event) {
if(!valid)
{
//stopEvent
event.preventDefault();
} else {
//submit your form
$("#form").submit();
}
});
单击“提交”按钮/图像后是否要禁用按钮 如果您使用的是
php
,您可以使用下面的代码或添加disabled=“disabled”
来禁用按钮,只要您将其保留在输入表单中即可
<?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?>
如何添加我的代码
如果将代码行与图像类型一起使用:
尝试:
单击表单内的按钮,默认情况下提交表单。要更改它,必须使用type=“button”定义一个按钮。然后,您可以在其中添加img元素。这是我找到的最好的方法
<form>
<button type="button" id="imageButton" onclick="javascript:autofill();">
<img src="images/arrow.png">
</button>
</form>
将attribute type=“button”添加到按钮标记解决了我的问题。根据问题的提问方式,这是正确的答案。欢迎使用堆栈溢出。通常的用法是解释代码为什么提供OP问题所要求的解决方案。添加了解释。谢谢你的启发。