2015-07-13 64 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>