After returning false, will all the following codes not be executed? Why does bbb still pop up when the button is clicked when the length is greater than 7?
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
window.onload=function(){
var oIpt1=document.getElementById('ipt1');
var oBtn1=document.getElementById('btn1');
oIpt1.onblur=function(){
if(oIpt1.value.length>7){
alert('aaa');
return false;
}
}
oBtn1.onclick=function(){
alert('bbb');
}
}
</script>
</head>
<body>
<input id="ipt1"></input>
<button id="btn1">提交</button>
</body>
</html>
滿天的星座2017-05-19 10:33:31
return false is to jump out of the current function oIpt1.onblur and does not affect the execution of the external oBtn1.onclick function
高洛峰2017-05-19 10:33:31
This is bound to the blur event. It has nothing to do with being bound to the click event
怪我咯2017-05-19 10:33:31
Define a variable to the outer function while returning. The internal one is false and the external one also changes to false. That’s OK