Javascript 如何使此脚本中的引用可单击链接?
我有这个脚本从Code升降机,它的工作非常好。 我想,如果下面的报价包含一个网址,那么它将成为可点击的。 任何帮助都会很好。 谢谢Javascript 如何使此脚本中的引用可单击链接?,javascript,Javascript,我有这个脚本从Code升降机,它的工作非常好。 我想,如果下面的报价包含一个网址,那么它将成为可点击的。 任何帮助都会很好。 谢谢 // ============================================== //版权所有2004年由CodeScreer.com //人人免费;但请在这个标题中离开。 // ============================================== var quote=new Array()//不要更改此值! //设置要显
// ==============================================
//版权所有2004年由CodeScreer.com
//人人免费;但请在这个标题中离开。
// ==============================================
var quote=new Array()//不要更改此值!
//设置要显示的报价,如下所示。
//要添加更多报价,请继续
//模式,添加到数组中。记得
//增加报价单[x]索引!
报价单[0]=”http://www.youtube.com/watch?v=zH6U5y086hw";
引文[1]=“理智是没有鞋带的金苹果。”;
引文[2]=“悔改!末日将至,亚马逊9.95美元。”;
引文[3]=“欺骗打喷嚏时,诚实脱口而出。”;
引文[4]=“糕点满足无法获得艺术的地方。”;
引号[5]=“请勿删除,以免您也被删除。”;
引用语[6]=“啊!青春!多么痛苦的背后。”;
语录[7]=“愿望就像有推进器的金鱼。”;
引用语[8]=“爱这条河的“美”,但要住在山上。”;
引文[9]=“发明是太多无用玩具之母。”;
// ======================================
//请勿更改此线以下的任何内容
// ======================================
var Q=报价单长度;
var whichquote=Math.round(Math.random()*(Q-1));
函数showQuotence(){document.write(Quotence[whichQuotence]);}
showquote();
这就是我要做的:
函数showQuotence(){
如果(QUOTE[whichQUOTE].substr(0,7)='http://'| | QUOTE[whichQUOTE].substr(0,8)=='https://')
文件。写(“”);
其他的
文件编写(引用[其中引用]);
}
在那里贴一个锚定标签。有点脏,但它根据提供的信息工作。如果您对字符串进行匹配并提取链接(允许自定义链接文本),可能会更好。模式匹配对于短编码url和使用jquery或javascript用链接和文本替换短代码非常有用。谢谢Elias。正是我想要的
<script language="JavaScript">
// ==============================================
// Copyright 2004 by CodeLifter.com
// Free for all; but please leave in this header.
// ==============================================
var Quotation=new Array() // do not change this!
// Set up the quotations to be shown, below.
// To add more quotations, continue with the
// pattern, adding to the array. Remember
// to increment the Quotation[x] index!
Quotation[0] = "http://www.youtube.com/watch?v=zH6U5y086hw";
Quotation[1] = "Sanity is a golden apple with no shoelaces.";
Quotation[2] = "Repent! The end is coming, $9.95 at Amazon.";
Quotation[3] = "Honesty blurts where deception sneezes.";
Quotation[4] = "Pastry satisfies where art is unavailable.";
Quotation[5] = "Delete not, lest you, too, be deleted.";
Quotation[6] = "O! Youth! What a pain in the backside.";
Quotation[7] = "Wishes are like goldfish with propellors.";
Quotation[8] = "Love the river's \"beauty\", but live on a hill.";
Quotation[9] = "Invention is the mother of too many useless toys.";
// ======================================
// Do not change anything below this line
// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>
function showQuotation(){
if(Quotation[whichQuotation].substr(0,7)=='http://' || Quotation[whichQuotation].substr(0,8)=='https://')
document.write('<a href="'+Quotation[whichQuotation]+'">'+Quotation[whichQuotation]+'</a>');
else
document.write(Quotation[whichQuotation]);
}