我需要使用 Javascript 验证表单
这是我的表格:
<form name="login" action="#" method="POST" onSubmit="return validasi()">
<div class=log>My Id</div><div class=log><input type="text" name="username"></div>
<div class=log>Password</div><div class=log><input type="password" name="sandi"></div>
<div class=log><input id="tombol" type="submit" value="Login" ></div>
</form>
...和 JS 验证:
<script language="javascript">
function validasi(form){
if (form.username.value == ""){
alert("Anda belum mengisikan Username.");
form.username.focus();
return (false);
}
if (form.sandi.value == ""){
alert("Anda belum mengisikan Password.");
form.sandi.focus();
return (false);
}
return (true);
}
</script>
但是,JS 不工作。请帮我解决它。