如果文本字段中未输入任何数据,如何有条件地阻止表单提交

How to conditionally prevent form submission if no data has been entered into the text fields?

本文关键字:有条件 表单提交 数据 字段 文本 未输 任何 输入 如果      更新时间:2023-09-26

我有这样的表格:

<form name="searchForm" action="" method="post">
    <input type="text" id="keywords" name="keywords"><br>
    <button type="submit" id="searchButton" name="searchButton" value="search">Search</button>    
</form>

我想确保除非文本字段中至少包含一个字符,否则永远不会提交此表单。如何继续?

我会灰显提交按钮。这里有一个关于它的过去的帖子:

灰色的提交按钮,直到表单填写完毕