Home  >  Article  >  Web Front-end  >  JavaScript method to determine whether DIV content is empty_javascript skills

JavaScript method to determine whether DIV content is empty_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:17:011973browse

1. Problem background

Determine whether the interior of the div is empty. If it is empty, give a no data prompt; otherwise, display the normal page

2. The effect diagram is as follows:

3. Design source code

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

The above is the editor’s introduction to JavaScript’s method of determining whether the DIV content is empty. I hope it will be helpful to you.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn