简体   繁体   English

我如何制作一个jQuery循环来更改链接的href属性?

[英]How do I make a jQuery loop which changes the href attribute of a link?

I've built a slideshow gallery from scratch using jQuery . 我已经使用jQuery从头开始构建了幻灯片库。 It can have any number of slides. 它可以有任意数量的幻灯片。 Under the slideshow I have a 'More info' button. 在幻灯片下方,我有一个“更多信息”按钮。 I would like this link to change every 5000ms to reflect the slide being show. 我希望此链接每隔5000ms更改一次,以反映正在显示的幻灯片。

I know I can use .attr to change the href value itself, it is just changing it at intervals of 5000ms to different things (on a loop!) that I'm completely at a loss with... 我知道我可以使用.attr来更改href值本身,它只是以5000ms的间隔将其更改为不同的内容(循环!),我完全不知所措...

Help would be greatly appreciated! 帮助将不胜感激!

Use a timer . 使用计时器

//Set Image to first picture by default.
$('#yourImageId').attr("src", imageSrcArray[0]);

var milliseconds = 5000;

//Call Function after 5 seconds to show second picture
var t=setTimeout("changeSlide();", milliseconds); 

//If you set the image's original src to your first array item, this will cause the first update in 5 seconds to display the second item.
var cnt=1; 

function changeSlide(){

    //update image src
    $('#yourImageId').attr("src", imageSrcArray[cnt]);

    t=setTimeout("changeSlide();", milliseconds);//Call Function Again after 5 seconds

    cnt++;

    //Check that cnt is within image array bounds
    if (cnt > imageSrcArray.length-1) cnt=0;

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jquery - 如何在链接中更改属性href的一部分? - Jquery - How to change part of attribute href in link? 如何更改链接的“href”属性使用jQuery具有特定的“href”? - How to change “href” attribute of link has specific “href” using jQuery? Jquery - 如果链接属性 href 包含我需要查找的字符串,如何删除链接或解开子元素? - Jquery - How to remove link or unwrap children element if link attribute href contain string that i need to find? 我该如何更改每个元素的每个“ href”属性的用户脚本? - How can I make a userscript that changes every 'href' attribute of every element? 如何使用 onchange 更改使用 jquery 显示(显示/隐藏)的列表? - How do I use onchange to make a changes to which list is shown (show/hide) by using jquery? 如何点击包含变量的链接到“href”属性? - How to click on a link which contains a variable into “href” attribute? 如何使用数据属性和jQuery使链接可以点击? - How can I use a data attribute and jQuery to make a link clickable or not? 如果 href 属性不是您想要的,如何制作重定向链接 - how to make a redirect link if the href attribute is not what you want 我如何退货 <link href=“” /> jQuery的href,ajax吗? - How would I return a <link href=“” /> href with jquery, ajax? 如何使用jQuery将下一个元素的ID设置为链接的href属性? - How to set id of next element into href attribute of link using jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM