小白学前端33
1.js表单验证时:
<form id="test-form" onsubmit="return checkForm()">
.......
<script type="text/javascript">
function checkForm(){
var username = document.getElementById("username").value;
var input_pwd = document.getElementById("input_pwd").value;
var pwdAgain = document.getElementById("pwdAgain").value;
var usernameRegexp =/\w{3,12}/;
var input_pwdRegexp =/.{6,20}/;
console.log(usernameRegexp.test(username));
console.log(input_pwdRegexp.test(input_pwd));
console.log(pwdAgain===input_pwd);
return false;
}
</script>
在页面运行的时候发现不能在控制台得到输出结果??
2.而且在form表单中onsubmit="checkForm()";与onsubmit="return checkForm()";的区别是?
onsubmit="checkForm()";
---
When you call function() you are saying to execute the function onSubmit.(在我这是checkForm())
When you say return function() you are saying to continue submit depending on the return value of function(). If function() returns false, submit doesnt continue
---

浙公网安备 33010602011771号