我有一个窗体里面有一个图像按钮,这个图像按钮正在提交表单。我如何覆盖这个功能?图像按钮里面的表单,不想提交
<form><input type="image" src="/images/arrow.png" id="imageButton" onClick="javascript:autofill();"/></form>
我有一个窗体里面有一个图像按钮,这个图像按钮正在提交表单。我如何覆盖这个功能?图像按钮里面的表单,不想提交
<form><input type="image" src="/images/arrow.png" id="imageButton" onClick="javascript:autofill();"/></form>
为什么不只是有图像?返回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" />
尝试使用event.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"'; ?>
如何添加我的代码
,如果您使用的代码行与图像类型:
尝试:
<form><input type="image" src="/images/arrow.png" id="imageButton" onClick="javascript:autofill();" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> /></form>
请从我(jagb)读this answer太多,如果你想使用的图像没有JavaScript中,需要
css
可以在那里找到为好。
点击表格内的按钮,默认提交表格。要改变它,你必须定义一个type =“button”的按钮。然后,你可以在里面添加img元素。这是我发现的最好方式。
<form>
<button type="button" id="imageButton" onclick="javascript:autofill();">
<img src="images/arrow.png">
</button>
</form>
您好,欢迎来到堆栈溢出。正常用法是为了解释为什么你的代码提供了OP问题所要求的解决方案。 – sweetfa 2015-04-18 21:03:29
添加说明。感谢启发。 – 2015-04-21 18:05:07
基于问题的方式问这是正确的答案 – 2013-07-01 12:08:33