<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><html><body><form id="api_crud_form" name="api_crud_form" action="https://www.google.es">Name: <input type="text" name="name" id="name"><br> <input type="submit" value="Send"></form></body></html><script type="text/javascript">$(document).ready(function () { $('#api_crud_form').on('submit', function (event) { event.preventDefault(); if ($('#name').val() == '') { alert("enter name"); } else{ alert("the data was sent"); } }); });</script>这是一个例子如果该字段为空,则这是一个有效示例,但如果插入空格则无效正如您在发送空格的示例中看到的
2 回答
莫回无
TA贡献1865条经验 获得超7个赞
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<form id="api_crud_form" name="api_crud_form" action="https://www.google.es">
Name: <input type="text" name="name" id="name"><br>
<input type="submit" value="Send">
</form>
</body>
</html>
<script type="text/javascript">
$(document).ready(function () {
$('#api_crud_form').on('submit', function (event) {
event.preventDefault();
if ($('#name').val().trim() == '') {
alert("enter name");
}
else{
alert("the data was sent");
}
});
});
</script>
添加回答
举报
0/150
提交
取消