Javascript 我需要获取主div中的div,如果其中的数据为空,则隐藏at div

Javascript 我需要获取主div中的div,如果其中的数据为空,则隐藏at div,javascript,Javascript,我有一个主跳水,里面有两个跳水。我需要检查一下,如果div的数据是空的,就不要显示它们。顺便说一句,数据来自API 以下是代码: <div id ="select"> <ul> <li><div id="product1" style="font-family:arial; font-size:13px; border-bottom:1px solid #b8b8b8; background-color:#eeeeee; pa

我有一个主跳水,里面有两个跳水。我需要检查一下,如果div的数据是空的,就不要显示它们。顺便说一句,数据来自API

以下是代码:

<div id ="select">
     <ul>
         <li><div id="product1" style="font-family:arial; font-size:13px; border-bottom:1px solid #b8b8b8; background-color:#eeeeee; padding:10px;">

               <strong>{$feed/API Feed_142197/__data["1-Title"]}</strong>
               <br/>
               <p>{$feed/API Feed_142197/__data["1-Desc"]}</p>

              <div style="display:inline; align:left; color:green; font-weight:bold;">{$feed/API Feed_142197/__data["1-Price"]}</div>

               <div style="display:inline; padding-left:80px; padding-right:5px;">click to call image</div></div>
         </li>


         <li><div id="product2" style="font-family:arial; font-size:13px; border-bottom:1px solid #b8b8b8; background-color:#eeeeee; padding:10px;">
              <strong>{$feed/API Feed_142197/__data["2-Title"]}</strong>
              <br/>
              <p>{$feed/API Feed_142197/__data["2-Desc"]}</p>
              <div style="display:inline; align:left; color:green; font-weight:bold;">{$feed/API Feed_142197/__data["2-Price"]}</div>
              <div style="display:inline; padding-left:80px; padding-right:5px;">click to call image</div></div>
         </li>

</div>

  • {$feed/API feed\u 142197/\u数据[“1-Title”]}
    {$feed/API feed_142197/___数据[“1-Desc”]}

    {$feed/API feed_142197/___数据[“1-Price”]} 单击以调用图像
  • {$feed/API feed\u 142197/\u数据[“2-Title”]}
    {$feed/API feed_142197/___数据[“2-Desc”]}

    {$feed/API feed_142197/___数据[“2-Price”]} 单击以调用图像
使用jQuery

var div1 = $('#product1'),
    div2 = $('#product2');

if (!(div1.text() || div2.text())) {
     $('#select').hide()
}

这是一款现代浏览器,无需库即可解决

var nodes = document.querySelectorAll('#select div:empty');
for (var i = 0, il = nodes.length; i < il; i++) {
    nodes[i].style.display = 'none';
}
var nodes=document.querySelectorAll('select div:empty');
对于(var i=0,il=nodes.length;i
关于您的代码,我可以看到2 div的情况两次。你是说没有id的两个div吗?你可以通过阅读and.和而不使用jQuery来找到问题的解决方案?如果OP甚至不知道jQuery是什么呢?如果呢?好吧,对他们来说,在浏览器中编写代码要困难得多。JSI实际上意味着您可能至少解释一下jQuery是什么,并提供一个链接。。。