2016-04-26 32 views
0

你能在我的網站上幫助我解決這個錯誤嗎?驗證器錯誤。你可以幫我嗎?

Error: document type does not allow element "div" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag

而且我發現這部分代碼:

<?php foreach ($this->categories as $cat){ 
      echo '<span>'.$cat->category_name_rus.' '; 
       if(count($cat->products)>0){ 
        echo '<div class="hover"><ul>'; 
         foreach ($cat->products as $product) { 
          echo '<li><a href="/product/'.$product->id.'"><div class="left_act">'.$product->product_name_rus.'</div><div class="right_act"></div></a></li>'; 
         } 
       echo '</ul><div></div></div>'; 
       } 
      echo '</span>'; 
     }?> 

有什麼不對?

+0

如何宥運行此腳本,顯示源代碼請。 – Naumov

+0

複製代碼的輸出並粘貼在這裏https://validator.w3.org/#validate_by_input – Chay22

+0

跨度是一個內聯元素,所以有跨度內一個div是一個壞主意,另外,它會更好,如果你巢跨越內部跨度並給內部跨度或跨度內div。 –

回答

0

原因:

關閉DIV的兩次沒有開格

所以請更改

echo '</ul><div></div></div>'; 

echo '</ul><div>'; 

更超過<span>標籤內嵌元件。 div不作爲子元素使用a標籤

0

從語義上講,您不應該有一個span標籤,其中包含塊元素,如divsHTML standard表示跨度中只應包含措辭元素。

Content model: Phrasing content.

而且from

Phrasing content is the text of the document, as well as elements that mark up that text at the intra-paragraph level. Runs of phrasing content form paragraphs.

0

請試試這個...

<?php foreach ($this->categories as $cat) : ?> 
    <div> 
     <span><?php echo $cat->category_name_rus.' '; ?></span> 
     <?php 
     if(count($cat->products)>0){ 
      ?> 
      <div class="hover"> 
       <ul> 
        <?php 
        foreach ($cat->products as $product) { 
         ?> 
         <li> 
          <a href="/product/".<?php echo $product->id;?> > 
           <div class="left_act"> 
            <?php echo $product->product_name_rus; ?> 
           </div> 
           <div class="right_act"> 

           </div> 
          </a> 
         </li> 
        <?php 
        } 
        ?> 
       </ul> 
      </div>'; 
     } 
    </div> 
<?php endforeach ?> 

希望它會幫助你....

相關問題