找到你要的答案

Q:How to make an HTML class containing links a link?

Q:如何使含有链接HTML的课吗?

The image and caption, in class story has two different links. Image points to one location and link to another.

I need to make whole class story into a link.

<div class="story">
<a href="link"> <img src="linkforimage"></a> 
<a href="link2">Caption for image </a>
</div>

I need a solution like this:

<a href="link">
  <div class="story">
    <a href="link"> <img src="linkforimage"></a> 
    <a href="link2">Caption for image </a>
  </div>
</a>

图像和标题,在课堂上有两个不同的链接。图像指向一个位置并链接到另一个位置。

我需要把整个班级的故事变成一个链接。

<div class="story">
<a href="link"> <img src="linkforimage"></a> 
<a href="link2">Caption for image </a>
</div>

我需要这样的解决方案:

<a href="link">
  <div class="story">
    <a href="link"> <img src="linkforimage"></a> 
    <a href="link2">Caption for image </a>
  </div>
</a>
answer1: 回答1:

Nesting a tags is a bad idea. I would use a delegate here. Have a wrapper a tag and in JS check which source span was clicked.

html

<a href="#" class="story">
    <span data-href="link"><img src="linkforimage"/></span> 
    <span data-href="link2">Caption for image</span>
</a>

js (jquery based)

$('.story').on('click', 'span', function() {
  document.location.href= $(this).data('href');
});

嵌套标签是个坏主意。我会在这里使用一个委托。有包装的标签和JS检查源跨点击。

HTML

<a href="#" class="story">
    <span data-href="link"><img src="linkforimage"/></span> 
    <span data-href="link2">Caption for image</span>
</a>

JS(jQuery的基础)

$('.story').on('click', 'span', function() {
  document.location.href= $(this).data('href');
});
answer2: 回答2:

You can't have anchor tag inside anchor tag. You can use onclick method to achieve your goal.

<div onClick="window.open(link);" class="story">
<a> <img src="linkforimage"></a> 
<a onClick="window.open(link2); event.stopPropagation();" >Caption for image </a>
</div>

EDIT jsfiddle

You can't have anchor tag inside anchor tag. You can use onclick method to achieve your goal.

<div onClick="window.open(link);" class="story">
<a> <img src="linkforimage"></a> 
<a onClick="window.open(link2); event.stopPropagation();" >Caption for image </a>
</div>

编辑JSFiddle

answer3: 回答3:

Clarifying the problem I am facing right now is that I am using embedly platform, where image comes from . So, I just post with link and image are parsed from the link by embedly. But, that ahref takes user to original web site. Caption takes user to the page with that content on my web site. I need to make of caption to the whole div.

So, I found the answer with CSS, I just added: style=" pointer-events: none;cursor: default;" on the link with image and style="cursor: pointer;" onclick="window.location='link'" on a class "story" in div.

澄清我现在面临的问题是,我用了深入的平台,图像是从哪里来的。所以,我只是后链接和图像解析从链接通过深入地。但是,这ahref以用户原创网站。标题将用户带到该网站上的内容。我需要做标题的全部

So, I found the answer with CSS, I just added: style=" pointer-events: none;cursor: default;" on the link with image and style="cursor: pointer;" onclick="window.location='link'" on a class "story" in div.

javascript  jquery  html  css  image