gpt4 book ai didi

javascript - 表单提交绕过 JavaScript 验证

转载 作者:行者123 更新时间:2023-12-02 19:11:05 27 4
gpt4 key购买 nike

下面的提交绕过了 JavaScript 验证。是因为 onclick 还是我遗漏了什么?

谢谢

表格

<form name="myprofile" action="do_update" method="post" onsubmit="return validate_submission(this.name)">
<input type="text" id="text_fullname" name="text_fullname" value="" maxlength="100" />
<div id="submit_button" onclick="document.myprofile.submit()">SUBMIT</div>
</form>

JS

function validate_submission(formname)
{
alert(formname); return false;
}

最佳答案

与其说您使用的是 onclick,不如说您使用的是 form_ref.submit(),它提交表单而不触发 submit 事件。

您的选择:

  • 使用真正的提交按钮(并且不要使用 JS 调用 submit())。这是最好的选择。它将显示在屏幕阅读器表单模式中。可以通过选项卡来实现。不开启JS就可以工作。
  • 在调用 submit() 之前调用验证函数并检查结果。

关于javascript - 表单提交绕过 JavaScript 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13701954/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com