2011-05-30 40 views
1

这里我的代码如何把<a>链接放在<span>的<a>?

<a href="http://linkurl" class="link" title="sometitle"> 
text link 

<span class="hidden-tooltip-data" style="display: none;"> <a 
href="http://www.google.ca"> my link here destroy everything </a 
</span> 
    </a> 

我用Poshy这里脚本

 $('.link').each(function() { 
     var tooltip = $(".hidden-tooltip-data",this).html(); 
     $(this).attr("title",""); 
    $(this).poshytip({ 
    content: function(updateCallback) { 
     return tooltip; 
      } 
     }); 
     }); 
+6
+0

这是错的,你为什么要那样做? – kobe 2011-05-30 18:06:01

+0

你的问题没有道理...... – VirtualTroll 2011-05-30 18:06:03

回答

4

嵌套的链接是非法的。这种情况在the HTML 4.01 Specification中明确提到。

+0

thx ..好吧我会改变我的插件哈哈大声笑xD – 2011-05-30 18:19:21

1

首先你不应该这样做的。原因在于儿童a被完全忽略,因为它在父母a之下。

我建议你刚刚制作span包含包含多达span根据需要两种不同的a标签。

1

不应该把链接放在另一个链接。

0

默认情况下,Poshytip将读取元素的title属性并将其用作工具提示内容。但是,您希望在提示中包含链接,如果JavaScript被关闭(并且无法访问),则将HTML放入title看起来会很难看。

你最好的办法是包括纯文本的title对下级的浏览器,包括在data属性(obvously逃逸标记)增强的提示内容:

<a href="..." class="link" title="basic content" data-tip="enhanced content &lt;a href=&quot;...&quot;&gt;link&lt;/a&gt;">...</a> 

 

$('.link').each(function() { 
    $(this).attr('title','').poshytip({ content: $(this).data('tip') }); 
}); 

在这样的属性中包含标记显然会变得有点混乱,所以如果你的提示有一个共同的格式,那么包含URL作为data属性和b在脚本中使用标记。

$('.link').each(function() { 
    $(this).attr('title','').poshytip({ content: '<a href="' + $(this).data('tiplink') + '">link</a>' }); 
});