相应归属链路随机背景图片? [英] Random background image with corresponding attribution link?

查看:143
本文介绍了相应归属链路随机背景图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有从5图像阵列显示一个随机的背景图像的页面。我想也有相应的归属链接在页面底部的形象,但我不知道如何使用JavaScript或PHP的做到这一点。这就是我现在:

 <脚本的src =// ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js类型=文/ JavaScript的&GT ;< / SCRIPT><脚本类型=文/ JavaScript的>
 变种图像= ['1.JPG','2.JPG','3.JPG','4.JPG','5.JPG'];
 $('身体')的CSS({'背景图像':'URL(/网站/默认/文件/图片/+图像[Math.floor(的Math.random()* images.length)] +') '});
< / SCRIPT>

这加载背景图片就好了,但有没有办法一个链接元素数组中的某个页面上的添加到每个图像和显示链接?


解决方案

 <!DOCTYPE HTML>
< HTML LANG =ENGT&;
< HEAD>
    <间的charset =UTF-8>
    <标题>< /标题>    < META NAME =视口CONTENT =WIDTH =设备宽度,初始规模= 1.0>
    < META HTTP-EQUIV =X-UA-Compatible的内容=IE =边缘>    <! - 使用Javascript / jQuery的 - >
    &所述; SCRIPT SRC =HTTP://$c$c.jquery.com/jquery-1.11.0.min.js>&下; /脚本>
< /头>
<身体GT;<一个ID =链接的href =#>< / A><脚本类型=文/ JavaScript的>
    变种图像= ['1.JPG','2.JPG','3.JPG','4.JPG','5.JPG'];
    变种链接= ['home.html做为','contact.html','about.html','product.html','gallery.html'];
    VAR文本= ['约','产品'的'家','接触','画廊​​'];
    VAR兰特= Math.floor(的Math.random()* images.length);    $('身体')的CSS({'背景图像':'URL(/网站/默认/文件/图片/+图像[兰德] +')'});
    $('#链接')ATTR('href属性,链接[兰德])。
    $('#链接')HTML(文[兰德]);
< / SCRIPT>< /身体GT;
< / HTML>

I have a page that displays a random background image from an array of 5 images. I want to also have the appropriate attribution link for that image on the bottom of the page, but I'm not sure how to do this with javascript or php. This is what I have now:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript" ></script>

<script type="text/javascript">
 var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg'];
 $('body').css({'background-image': 'url(/sites/default/files/images/' + images[Math.floor(Math.random() * images.length)] + ')'});
</script>

this loads the background image just fine, but is there a way to add a link element to each image in the array and display the link somewhere on the page?

解决方案

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <!-- javascript/jQuery -->
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>

<a id ="link" href="#"></a>

<script type="text/javascript">
    var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg'];
    var links = ['home.html', 'contact.html', 'about.html', 'product.html', 'gallery.html'];
    var text = ['home', 'contact', 'about', 'product', 'gallery'];
    var rand = Math.floor(Math.random() * images.length);

    $('body').css({'background-image': 'url(/sites/default/files/images/' + images[rand] + ')'});
    $('#link').attr('href', links[rand]);
    $('#link').html(text[rand]);
</script>

</body>
</html>

这篇关于相应归属链路随机背景图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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