将图像文件添加到动态数组中 [英] To add the image file into dynamic array
本文介绍了将图像文件添加到动态数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我指定的文件夹位置中有很多gif文件("D \ Picture \")
我想将该gif文件添加到使用Java脚本指定位置来创建动态数组.
我将如何使用Java脚本编程语言解决上述问题???
请帮我解决以上问题.....
I have a lot of gif files in my specifying folder location(''D\Picture\'')
I want to add that gif files to creating dynamic array from specifying location using java script.
How will i solve the above problem by java scripts programming language?????
Please help me anybody for above problems.....
推荐答案
尝试一下:
Try this:
var images = {
0: 'images/pic1.png',
1: 'images/pic2.png',
2: 'images/pic3.png'
}
function setImage(elementId, imageIndex) {
document.getElementById(elementId).src = images[imageIndex];
}
您可以使用类似于以下的代码创建阵列服务器端:
You can create the array server side using code similar to this:
string[] files = System.IO.Directory.GetFiles("d:\\picture");
System.Text.StringBuilder sb = new StringBuilder();
string relativePath = "images";
int fileIndex = 0;
sb.AppendLine("var images = {");
foreach (string file in files)
{
System.IO.FileInfo fi = new FileInfo(file);
sb.AppendLine((fileIndex > 0 ? "," : "") + fileIndex + ": '" + relativePath + "/" + fi.Name + "'");
}
sb.AppendLine("};");
System.Web.UI.HtmlControls.HtmlGenericControl script = new System.Web.UI.HtmlControls.HtmlGenericControl("script");
script.Attributes.Add("language", "javascript");
script.Attributes.Add("type", "text/javascript");
script.InnerText = sb.ToString();
this.Controls.Add(script);
这篇关于将图像文件添加到动态数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文