您的位置:首页 > 技术中心 > 前端框架 >

怎么判断jquery div是否为空

时间:2021-01-25 12:46

jquery div是否为空的判断方法:首先在html页面中引入jQuery.min.js;然后引入jQuery和searchNull.js;最后在html页面中的任意一个div上添加id属性为“no_content”即可实现判断。

本教程操作环境:windows7系统、jquery1.2.6版本,DELL G3电脑。

推荐:jquery视频教程

用jQuery判断div是否为空的方法

1、在html页面中引入jQuery.min.js,版本最好用1.2版以上的

2、searchNull.js代码如下

function validate() {
   //var content = $("#content").html();
   var noContent = $("#no_content").html();
   // if (content == null || content.length == 0) {
   //     alert("content:" + conten);
   // }
   if (noContent == null || noContent.length == 0) {
      $("#no_content").append("<p>对不起,没有相关的查询结果</p>");
      alert("对不起,没有相关的查询结果");
       window.location.href='/Shop';
   }
}
 
window.onload = function () {
validate();
}

3、用法如下

先引入jQuery和searchNull.js

再在html页面中的任意一个div上添加id属性为no_content

示例:

<div id="no_content">
</div>

以上就是怎么判断jquery div是否为空的详细内容,更多请关注www.gxlsystem.com其它相关文章!

本类排行

今日推荐

热门手游