如果 div 有内容显示 div [英] if div has content show div

查看:63
本文介绍了如果 div 有内容显示 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这就是我所拥有的......它工作正常,但它寻找的是一个词而不是内容.我只是想让它在有任何内容时显示..

 $(document).ready(function(){if ($("#box3:contains('Product')").length) {$('#third').show();}});

我不认为你需要这个 html

它寻找产品"我如何让它只寻找内容>0

<div class="tab" id="second"><div class="tabtxt"><a>灵感</a>

<div class="tab" id="third" style="display:none"><div class="tabtxt"><a>注意事项</a>

<div class="boxholder"><div style="overflow: hidden; display:block" class="box" id="box1"><div style="padding: 10px; line-height:16px">%%面板.产品描述%%

<div style="overflow: hidden; display:none" class="box" id="box2"><div style="padding: 10px; line-height:16px">%%面板.产品保修%%

<div style="overflow: hidden; display:none" class="box" id="box3"><div style="padding: 10px; line-height:16px">%%面板.UPC%%

它是一个 interspire 购物车,因此 %%panel.upc%% 调用通过管理面板插入的内容.在这种情况下,如果什么都没有......它在代码中显示为空格(在浏览器中查看源代码).

解决方案

如果要检查text,可以使用text()方法:

 $(document).ready(function(){如果 ($("#box3").text().length > 0) {$('#third').show();}});

或者对于 html:

 $(document).ready(function(){如果 ($("#box3").html().length > 0) {$('#third').show();}});

ok heres what i have... it works fine but it looks for a word rather than content. i just want it to show when there is any content..

 $(document).ready(function(){
       if ($("#box3:contains('Product')").length) {
          $('#third').show();
       }                                           
    });

i dont think you need the html for this

it looks for 'Product' how do i make it just look for content >0

<div id="first" class="tab" >
    <div class="tabtxt">
        <a>DETAILS</a>
    </div>
</div>
<div class="tab" id="second">
    <div class="tabtxt">
        <a>INSPIRATION</a>
    </div>
</div>
<div class="tab" id="third" style="display:none">
    <div class="tabtxt">
        <a>NOTES</a>
    </div>
</div>

<div class="boxholder">
    <div style="overflow: hidden; display:block" class="box" id="box1">
        <div style="padding: 10px; line-height:16px">
            %%Panel.ProductDescription%%
        </div>
    </div>
    <div style="overflow: hidden; display:none" class="box" id="box2">
        <div style="padding: 10px; line-height:16px">
            %%Panel.ProductWarranty%%
        </div>
    </div>
    <div style="overflow: hidden; display:none" class="box" id="box3">
        <div style="padding: 10px; line-height:16px">
            %%Panel.UPC%%
        </div>
    </div>
</div>

its an interspire shopping cart so the %%panel.upc%% calls in something inserted through the admin panel. in this case if there is nothing.. it shows as blank space in the code (viewing source in browser).

解决方案

If you want to check for text, you can use the text() method:

 $(document).ready(function(){
   if ($("#box3").text().length > 0) {
     $('#third').show();
   }                                           
 });

Or for html:

 $(document).ready(function(){
   if ($("#box3").html().length > 0) {
     $('#third').show();
   }                                           
 });

这篇关于如果 div 有内容显示 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆