如何使用JQuery Wrapper向图像添加简单的超链接 [英] How to add a simple hyperlink to images using JQuery Wrapper

查看:101
本文介绍了如何使用JQuery Wrapper向图像添加简单的超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是编码人员,我需要一个简单的解决方案来将html文档中的超链接添加到jQuery图像..

I'm not a coder and I need a simple solution to adding a hyperlink in an html document to jQuery images ..

以下内容不起作用,所以我想它比以下内容更复杂...

the following does not work so I guess it's more complex that the following ...

<div class="slider-wrapper">
                    <div class="slider">
                        <ul class="items">
                          <li> <a href="http://url/index.php"><img src="images/slider-img-name.jpg" alt="name" /></a>
                          </li> 

有没有简单的方法可以完成这项工作?

Is there an easy way to make this work?

推荐答案

这应该可行,您只需要添加任意数量的链接,但请记住,对于每个img,您必须具有一个相应的链接,否则代码会失败

This should work, you just need to add as many links as you want but bear in mind that for each img you must have a corresponding link, otherwise the code will fail

<script>
    var links = new Array();
    links[0] = "http://www.google.com";
    links[1] = "http://www.yahoo.com";
    links[2] = "http://www.bing.com";

    $(document).ready(function(){
        $('.items a').each(function(){
            index = $(this).parent().index();
            $(this).attr("href",links[index]);
        });
    });
</script>

<ul class="items">
    <li> <a href=""><img src="images/slider-img-name.jpg" alt="name" /></a></li>
    <li> <a href=""><img src="images/slider-img-name.jpg" alt="name" /></a></li>
    <li> <a href=""><img src="images/slider-img-name.jpg" alt="name" /></a></li>
</ul>

这篇关于如何使用JQuery Wrapper向图像添加简单的超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆