Check if the input box is empty

need:

  When the input box loses focus: judge, if the content of the input box is empty, get the focus; otherwise, the content of the input box will pop up.

<!DOCTYPE html>
<html>
<head>
    <title>Determine whether the input is empty</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
    输入框:<input type="text" name="shurukuang" id="inputbox">
    <script type="text/javascript">
        // When the input box loses focus: judge   
        // If the content of the input box is empty, get the focus; 
        // If the content of the input box is not empty, the content of the input box will pop up 
        $( function () {
            $('#inputbox').blur(function(event) {
                if ($(this).val()=='') {
                    $(this).focus();
                }else{
                    alert($(this).val());
                }
            });
        })
    </script>
</body>
</html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324736483&siteId=291194637