JQuery实现Input失去焦点内容为空时背景变红

首次发布:2017-10-11 13:24

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <script src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(function () {
            $(':text').blur(function () {
                if ($(this).val().length == 0) {
                    $(this).css('backgroundColor', 'red');
                } else {
                    $(this).css('backgroundColor', '');
                }
            });
        });
    </script>
</head>
<body>
    <input /><input /><input /><input />
</body>
</html>