码迷,mamicode.com
首页 > 其他好文 > 详细

判断input框是否为空

时间:2018-04-24 11:18:49      阅读:504      评论:0      收藏:0      [点我收藏+]

标签:获取   pps   输入   type   jquer   style   input框   function   rip   

需求:

  当input框失去焦点时:判断,如果输入框内容为空则获取焦点;否则弹出输入框的内容。

<!DOCTYPE html>
<html>
<head>
    <title>判断input是否为空</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">
        // 输入框失去焦点时:判断  
        // 如果输入框内容为空则获取焦点;
        // 如果输入框内容不为空则弹出输入框的内容
        $(function () {
            $(‘#inputbox‘).blur(function(event) {
                if ($(this).val()==‘‘) {
                    $(this).focus();
                }else{
                    alert($(this).val());
                }
            });
        })
    </script>
</body>
</html>

 

判断input框是否为空

标签:获取   pps   输入   type   jquer   style   input框   function   rip   

原文地址:https://www.cnblogs.com/myunYao/p/8926153.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!