【问题标题】:jQuery :empty not working in JadejQuery :empty 在 Jade 中不起作用
【发布时间】:2013-03-10 17:33:09
【问题描述】:

我的页面上有一个用于信息消息的 div,但如果它为空,我希望它不可见。 我在布局文件中使用了以下 jQuery 脚本,但它似乎不起作用。我得到了一个空的蓝色盒子,但我希望它隐藏起来,除非里面有内容。

script(type='text/javascript')
    $('#info:empty').hide();

实际的 Jade 文件只有:

extends layout

block head
    title Test page

block content
    if (message)
        #info= message

我有另一个工作的 jQuery 脚本可以淡出整个 div,所以我不认为这是布局文件的问题,但无论如何:

head
    link(href='http://fonts.googleapis.com/css?family=Open+Sans', rel='stylesheet', type='text/css')
    link(href="/stylesheets/style.css", type="text/css", rel="stylesheet")
    script(type='text/javascript', src="http://code.jquery.com/jquery-1.9.1.min.js");
    script(type='text/javascript')
        $(document).ready(function(){
           setTimeout(function(){
          $("#info").fadeOut("slow", function () {
          $("#info").remove();
              });

        }, 2000);
         });
    script(type='text/javascript')
        $('#info:empty').hide();
    meta(http-equiv='Content-Type', content='text/html; charset=utf-8')
    block head

body
    block content

【问题讨论】:

    标签: jquery pug


    【解决方案1】:

    将它移动到文档中)。准备好它会触发。

        script(type='text/javascript')
            $(document).ready(function(){
               setTimeout(function(){
              $("#info").fadeOut("slow", function () {
              $("#info").remove();
                  });
    
            }, 2000);
             $('#info:empty').hide();
            });
    

    【讨论】:

      猜你喜欢
      • 2016-05-18
      • 2020-08-13
      • 2015-10-03
      • 1970-01-01
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      相关资源
      最近更新 更多