日期:2014-05-16  浏览次数:20385 次

JS实现 友情连接

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("