JS复习:通过表单提交触发方法
这是最简单的表单提交触发前端JS的验证方法。
HTML部分:
<form onsubmit="return validateForm()">
<label for="name">姓名:</label>
<input type="text" id="name" name="name"><br><br>
<input type="submit" value="提交">
</form>
JS部分:
function validateForm() {
var name = document.getElementById("name").value;
if (name == "") {
alert("姓名不能为空");
return false;
}
}
论外:
Today's comments have reached the limit. If you want to comment, please wait until tomorrow (UTC-Time).
There is 18h42m48s left until you can comment.