Home > Web Front-end > JS Tutorial > Analysis and solutions to the causes of errors in obtaining the internal content of DIV_javascript skills

Analysis and solutions to the causes of errors in obtaining the internal content of DIV_javascript skills

WBOY
Release: 2016-05-16 15:17:04
Original
1409 people have browsed it

1. Error description

2. Error reason

To add elements to the div, use append();

$("#divStyle").append("<div><label>_data[i].name</label></div>");
Copy after login

Append contains dynamic data. When the request data is empty, obtain and determine the content in the div:

var divContent = $("#divStyle").html();
if(divContent == null || divContent.length == 0)
{
$("#divStyle").append("<div><img src='/images/head.png'></div>");
}
Copy after login

I never entered the if during judgment. Later, I used the console to debug and found that even if there was no data, there were a lot of spaces and line breaks inside the div

3. Solution

(1) Use JS hiding method

When the requested data is judged to be empty, the no-data prompt image will be displayed, otherwise the no-data prompt image will be hidden;

(2) Use JsViews to request data method

As mentioned above, this article introduces to you the analysis and solutions to the causes of errors in obtaining the internal content of DIV. I hope it will be helpful to you.

Related labels:
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