Home  >  Q&A  >  body text

javascript - I don’t know much about JS. Ask a code question

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>
phpcn_u1582phpcn_u15822686 days ago468

reply all(4)I'll reply

  • 滿天的星座

    滿天的星座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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:33:31

    That is the code after the current method will not be executed...

    reply
    0
  • 高洛峰

    高洛峰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

    reply
    0
  • 怪我咯

    怪我咯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

    reply
    0
  • Cancelreply