Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 15:17:041359browse

1. Error description

2. Error reason

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

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

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>");
}

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.

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