每次刷新都会使用JQuery更改横幅 [英] On every refresh change the banner using JQuery
本文介绍了每次刷新都会使用JQuery更改横幅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是Jquery的初学者,我需要创建一个横幅,需要在每次刷新时更改。就像我将在应用程序文件夹中有一组图像,我必须一次在主页上显示它们,如果我刷新页面然后应显示下一个图像。
使用JQuery ...
如果javascript也没问题...
Hi everyone,
I'm beginer to Jquery, i have a requirement of creating a banner, that needs to be changed on every refresh. like i will have a collection of images in a application folder , i have to display them on home page on at a time, if i refresh the page then next image should display.
Using JQuery...
If javascript also no problem...
推荐答案
他们是否需要按特定顺序加载或者它可以是随机的吗?
如果随机可以做:
Do they need to load in a certain order or can it be random?
If random can just do:
var imageNo = Math.floor((Math.random()*5)+1); /* Change the 5 to the amount of images you have */
( .flag-img)。attr( src, bannerimage - + imageNo + 。jpg); / * 图片必须命名为bannerimage-1.jpg,bannerimage-2.jpg等,或者您选择的任何约定* /
(".banner-img").attr("src", "bannerimage-" + imageNo + ".jpg"); /* Images must be named bannerimage-1.jpg, bannerimage-2.jpg, etc or any convention of your choosing*/
然后只需将banner-img类添加到你的img元素所在的横幅将出现。
Then just add the class of "banner-img" to your img element where the banner will appear.
<img class="banner-img" />
假设您的横幅存储在根目录下的图像文件夹下的滑块中。
在pageload上调用以下方法
private void LoadImage()
{
string imagePath =〜/ images / slider /;
string imageSource = SiteBaseUrl +images / slider /;
string PhotoFilePath = Server.MapPath(imagePath);
string allimg =;
st ring fileSlide = string.Empty;
string fileName = string.Empty;
DirectoryInfo di = new DirectoryInfo(PhotoFilePath);
FileInfo [] rgFiles = di.GetFiles(*。*);
foreach(文件信息在rgFiles中)
{
fileSlide = @ ;
allimg + = fileSlide;
}
allimg.Replace(' ,\);
Literal1.Text = allimg + @
Assume your banners are stored in slider under image folder under root directory.
Call this following method on pageload
private void LoadImage()
{
string imagePath = "~/images/slider/";
string imageSource = SiteBaseUrl + "images/slider/";
string PhotoFilePath = Server.MapPath(imagePath);
string allimg = "";
string fileSlide = string.Empty;
string fileName = string.Empty;
DirectoryInfo di = new DirectoryInfo(PhotoFilePath);
FileInfo[] rgFiles = di.GetFiles("*.*");
foreach (FileInfo fi in rgFiles)
{
fileSlide = @"";
allimg += fileSlide;
}
allimg.Replace("'", "\"");
Literal1.Text = allimg + @"
;
}
使用以下JQuery
";
}
use this following JQuery
这篇关于每次刷新都会使用JQuery更改横幅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文