php - 使用 jquery cycle plugin for transitions 动态添加超链接到图像

标签 php jquery css jquery-plugins jquery-cycle

我正在使用 jquery 制作幻灯片 cycle plugin对于过渡。 现在一切正常,直到我向图像添加超链接。如果用户希望添加超链接,我会尝试添加超链接,所以我的控制台中为每个图像都有一个设置按钮。如果用户选择超链接并单击设置,它应该设置。现在超链接设置正确,但是,然后将转换应用于 anchor 标签而不是 img 标签。 当我设置链接时,img 标签像这样包裹在 anchor 标签内。

     <a href="www.google.com" id="link" class="link"> 
        <img id="imgBoxRot_1_1" style="width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; display: none; z-index: 3; opacity: 0;" src="http://localhost/images/layout/slideShow/gallImg1.jpg">
     </a>

我像这样动态地创建这个 anchor 标签,并将它附加到图像上。

    var newA = document.createElement("a");
    newA.setAttribute("id","lnkImgRotImg_"+iCount+"_"+idT);
    newA.setAttribute("href",document.getElementById(lnk).value);
    newA.setAttribute("class","aTransLink");
    newA.setAttribute("target","_blank");   

在设置 anchor 标签之前,插件工作正常并应用了过渡,但是在向图像添加 anchor 之后,过渡应用于 anchor 标签而不是图像。我该如何解决这个问题?
感谢抽空。

最佳答案

在研究了插件文档后我了解到,该插件默认应用于 第一个标签,该标签位于其所应用的 div 内。
也就是说,如果我们有

<div class="">
     <img></img>
     <img></img>         
</div>    

现在,如果我像这样在图像周围包裹一个 anchor ,

<div class="">
     <a href="">
       <img></img>
     </a>

     <img></img>         
</div>  

该插件混淆了图像标签和 anchor 标签,并将转换应用到 anchor 而不是图像标签(因为它是应用循环插件的 div 之后的第一个).因此,我最初将所有图像都包装在一个 anchor 标记中(之前我动态添加 anchor )并将插件应用于 anchor 本身而不是图像标记。

关于php - 使用 jquery cycle plugin for transitions 动态添加超链接到图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12668870/

相关文章:

javascript - Jquery - 在共享相同类名的其他元素之间选择一个元素(单击时)

javascript - Append within Append, Iframe within Append in Jquery

html - float 输入的标签索引

css - 在悬停时更改图像移动图像

php mysql错误,没有上传数据

php - 德鲁帕尔 6 : Views: Listing taxonomy terms with tagged nodes underneath

php - 部署生产 Laravel 5.2 应用程序的正确步骤是什么?

php - 用于转换和压缩视频的 ffmpeg 库

javascript - 如何一次只显示一个div?

javascript - 如何在课后删除空元素?(jQuery)