2015-07-13 52 views
-1

我不是很喜歡HTML,我有以下問題。如何在HTML中的div上插入鏈接?

我有這樣的外格:

<div data-wow-delay="0.25s" class="clearfix service-list odd wow fadeInLeft animated" style="visibility: visible; animation-delay: 0.25s; animation-name: fadeInLeft;"> 
    <div class="service-image"> 
     <img alt="test 1" src="http://localhost/onyx/wp-content/themes/accesspress-parallax/images/no-image.jpg"> 
    </div> 

    <div class="service-detail"> 
     <h3>test 1</h3> 
     <div class="service-content"> 
      <p>https://it.wikipedia.or /wiki/Pagina_principale</p> 
      <p>and</p> 
      <p>https://www.google.it/</p> 
      <p>&nbsp;</p> 
     </div> 
    </div> 
</div> 

所以現在我想添加一個鏈接到外部DIV。什麼是最好的方式來做到這一點?

+0

包裝在一個錨標記? – Pete

+2

你到底想做什麼? OO不清楚...一個例子? (http://jsfiddle.net) – Julo0sS

+0

皮特也不錯。 – Raghavendra

回答

0

看看這個fiddle

  1. 通過document.getElementById()獲得的方法。
  2. 設定值爲innerHTML

以下是摘錄。

document.getElementById("external").innerHTML = "<a href='http://www.google.com'> Google </a>";
<div id="external" data-wow-delay="0.25s" class="clearfix service-list odd wow fadeInLeft animated" style="visibility: visible; animation-delay: 0.25s; animation-name: fadeInLeft;"> 
 
    <div class="service-image"> 
 
    <img alt="test 1" src="http://localhost/onyx/wp-content/themes/accesspress-parallax/images/no-image.jpg"> 
 
    </div> 
 

 
    <div class="service-detail"> 
 
    <h3>test 1</h3> 
 
    <div class="service-content"> 
 
     <p>https://it.wikipedia.or /wiki/Pagina_principale</p> 
 
     <p>and</p> 
 
     <p>https://www.google.it/</p> 
 
     <p>&nbsp;</p> 
 
    </div> 
 
    </div> 
 
</div>

+0

我可以不使用JavaScript嗎? – AndreaNobili

+0

如果這是你的問題,那麼你應該谷歌「鏈接在HTML」 –

+0

看到這[[小提琴](http://jsfiddle.net/shrinivas93/emt34tu2/1/))。 –

0

您可以使用a元素,並給他atrribute display:block

a{ 
 
    display:block; 
 
    width: 200px; 
 
    height: 100px; 
 
    text-align: center; 
 
    background:yellow; 
 
}
<a href="#"> MY BLOCK LINK </a>