JS部分:
<script language="javascript">
<!--
String.prototype.IsNullOrEmpty = function() {
if(this == null || this == "")
{ return true; }
return false;
}
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
function LinksObj(type,title,href,isNewWindowOpen,imgSrc) {
if(typeof(type)!="number" || (type!=1 && type!=2)) { type=1; }
if(href.IsNullOrEmpty()){ href="#"; }
if(typeof(isNewWindowOpen)!="boolean") { isNewWindowOpen = false; }
if(type==1)
{
if(imgSrc.IsNullOrEmpty())
{
var defaultImgSrc = 'http://192.168.1.2/Nice/images/photo/huhu.gif';
imgSrc = defaultImgSrc;
}
else
{
if(imgSrc.toLowerCase().indexOf("http://") >=0 || imgSrc.toLowerCase().indexOf("www") >= 0)
{}
else
{ imgSrc = 'http://192.168.1.2/Nice/'+imgSrc; }
}
}
else
{ imgSrc = null; }
return new Array(title,href,isNewWindowOpen,imgSrc);
}
function LinksClass() {
var ImgLinks = new Array();
var TextLinks = new Array();
this.AddImg = function(title,href,isNewWindowOpen,imgSrc) {
ImgLinks.push(new LinksObj(1,title,href,isNewWindowOpen,imgSrc));
}
this.AddText = function(title,href,isNewWindowOpen) {
TextLinks.push(new LinksObj(2,title,href,isNewWindowOpen,null));
}
LinksClass.prototype.GetImg = function(index,subIndex) {
if(index < 0 || index > ImgLinks.length) { return null;}
if(subIndex < 0 || subIndex > 3) { return null;}
return ImgLinks[index][subIndex];
}
LinksClass.prototype.GetText = function(index,subIndex) {
if(index < 0 || index > TextLinks.length) { return null;}
if(subIndex < 0 || subIndex > 3) { return null;}
return TextLinks[index][subIndex];
}
this.length = function(type) {
if(type==1)
{return ImgLinks.length;}
return TextLinks.length;
}
this.ImgLength = ImgLinks.length;
this.TextLength = TextLinks.length;
this.AppendHtmlToId = function(id,type,title,href,isNewWindowOpen,imgSrc,imgWidth,imgHeight) {
var html = "";
var target ="";
var IdObj = $(id);
if(isNewWindowOpen) { target='_blank'; }
if(type==1)
{
html = '<a href="'+href+'" target="'+target+'" title="'+title+'" class="img_a"><img src="'+imgSrc+'" width="'+imgWidth+'" height="'+imgHeight+'"></a>';
}
else if(type==2)
{
if(IdObj.innerHTML.toString().IsNullOrEmpty())
{ html = '<A href="'+href+'" target="'+target+'">'+title+'</A>'; }
else
{ html = '| <A href="'+href+'" target="'+target+'">'+title+'</A>';}
}
else
{
html = 'Undefine';
}
IdObj.innerHTML = IdObj.innerHTML + html;
}
}
var Links = new LinksClass(); //实例连接类
function LoadLinksData()
{
/*加载数据*/
Links.AddImg("图片连接标题","#",true,"images/photo/title.gif");
Links.AddImg("征途","#",true,"images/photo/zt.gif");
Links.AddImg("魔兽世界","#",true,"images/photo/wow.gif");
Links.AddImg("网易免费邮","#",true,"images/photo/mailwy.gif");
Links.AddImg("新浪免费邮","#",true,"images/photo/mailsina.gif");
Links.AddImg("搜狐免费邮","#",true,"images/photo/mailsohu.gif");
Links.AddImg("MSN免费邮","#",true,"images/photo/mailhotmail.gif");
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
Links.AddText("文字连接标题","#",true);
}
function LoadingLinks()
{
//装载图片连接
var imgLength = Links.length(1);
for(var a=0;a < imgLength;a++)
{
Links.AppendHtmlToId("ImgLinks",1,Links.GetImg(a,0),Links.GetImg(a,1), Links.GetImg(a,2),Links.GetImg(a,3),84,27);
}
//装载文本连接
var textLength = Links.length(2);
for(var a=0;a < textLength;a++)
{
Links.AppendHtmlToId("TextLinks",2,Links.GetText(a,0),Links.GetText(a,1),Links.GetText(a,2),null,0,0);
}
}
window.onload = function() {
LoadLinksData();
LoadingLinks();
}
-->
</script>
HTML部分:
<div class="co_content">
<h1>友情连接</h1>
<div class="content_tit">图片链接</div>
<div class="content_list" id="ImgLinks"></div>
<div class="content_tit">文字链接</div>
<div class="content_list" id="TextLinks"></div>
</div>