如何判断DIV中的内容为空

如何判断DIV中的内容为空


1、问题背景

     判断div内部是否为空,如果为空,给出无数据提示;否则显示正常页面


2、设计源码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>如何判断DIV中的内容为空</title>
<script type="text/javascript" src="jquery-2.2.0.js"></script>
<script type="text/javascript">
    $(function(){
		$("#content").append("<div id='dv'>您好!</div>");
	    $("#btn").click(function(){
		      var content = $("#content").html();
			  var noContent = $("#no_content").html();
			  if(content == null || content.length == 0)
			  {
				  alert("content:"+conten);  
			  }
			  
			  if(noContent == null || noContent.length == 0)
			  {
				  alert("noContent:"+noContent);
			  }
		});
	});
</script>
</head>

<body>
   <div id="content"></div>
   <div id="no_content"></div>
   <input type="button" id="btn" value="判读DIV为空"/>
</body>
</html>

3、实现结果


原文地址:https://www.cnblogs.com/hzcya1995/p/13314252.html