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

<!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>

评论