<html>
<head>
<title>检测对象是否为空</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="http://www.imooc.com/data/jquery-1.8.2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="divtest">
<div class="title">
<span class="fl">检测对象是否为空</span>
</div>
<div class="content"></div>
</div>
<script type="text/javascript">
$(function () {
var obj = { "姓名": "土豪一族" };
var strTmp = "您定义了一个:";
if (?) { //检测是否为空
strTmp += "空对象";
}
else {
strTmp += "非空对象";
}
$(".content").html(strTmp);
});
</script>
</body>
</html>
#divtest
{
width: 282px;
}
#divtest .title
{
padding: 8px;
background-color: Blue;
color: #fff;
height: 23px;
line-height: 23px;
font-size: 15px;
font-weight: bold;
}
#divtest .content
{
padding: 8px;
background-color: #fff;
font-size: 13px;
}
.fl
{
float: left;
}
.fr
{
float: right;
}