我有来自 codelifter 的这个脚本,它运行得很好。 我希望如果下面的引用包含一个网址,那么它将变得可点击。 任何帮助都会很棒。 谢谢
<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>
最佳答案
这就是我要做的:
- 假设引用以 http(s)://开头
- 在 ShowQuotation 中:
使用正则表达式来识别此类字符串。可能不必要地复杂。检查 length-7 子字符串是否为http://
或 length-8 子字符串是否为https://
,假设其余部分都是 URL 的一部分 - 将其设为链接
关于javascript - 如何使该脚本中的引文成为可点击链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10166938/