JavaScript判斷DIV內容是否為空白的方法,javascriptdiv

來源:互聯網
上載者:User

JavaScript判斷DIV內容是否為空白的方法,javascriptdiv

1、問題背景

判斷div內部是否為空白,如果為空白,給出無資料提示;否則顯示正常頁面

2、實現如下所示:

3、設計源碼

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

以上所述是小編給大家介紹JavaScript判斷DIV內容是否為空白的方法,希望對大家有所協助。

您可能感興趣的文章:
  • js判斷FCKeditor內容是否為空白的兩種形式
  • js判斷滑鼠同時離開兩個div的思路及代碼
  • js實現數組去重、判斷數組以及對象中的內容是否相同
  • JS判斷文字框內容改變事件的簡單一實例
  • js判斷文字框輸入的內容是否為數字

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.