【问题标题】:Input type submit with onclick fuction return false does not stop submitting form [duplicate]使用onclick函数返回false的输入类型提交不会停止提交表单[重复]
【发布时间】:2021-09-07 16:26:42
【问题描述】:

我有一个这样的“提交”类型输入:

<input id="submit" type="submit" onClick="validation('<?php echo $no_id; ?>',event,this.id); "/>


function validation (no_id) {
     alert("FUNCTION WAS TRIGGERED");
     some code here 
     if (error) return false;
}

我可以看到警报消息,但它不会阻止表单提交。

【问题讨论】:

  • 是的,但是在看到这个 SO 问题之前我已经添加了我的修复程序。也谢谢你通知我。

标签: javascript


【解决方案1】:

原来我只需要在我的 onClick 中添加一个 return 关键字:

<input id="submit" type="submit" onClick="return validation('<?php echo $no_id; ?>',event,this.id); "/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 2016-04-29
    相关资源
    最近更新 更多