Home > Web Front-end > JS Tutorial > body text

JavaScript method to determine whether DIV content is empty_javascript skills

WBOY
Release: 2016-05-16 15:17:01
Original
1971 people have browsed it

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> 
Copy after login

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.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template