您的位置:首页 > 其它

如何判断DIV中的内容为空

2017-06-27 13:49 253 查看
如何判断DIV中的内容为空

1、问题背景

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

2、设计源码

[java] view
plain copy

 print?

<!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、实现结果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: