0

私は codelifter からこのスクリプトを持っていますが、うまく機能します。以下の引用に URL が含まれていれば、クリック可能になると思います。どんな助けでも素晴らしいでしょう。ありがとう

<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>
4

2 に答える 2

1
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]);
}
于 2012-04-16T00:08:50.000 に答える
1

これは私がすることです:

  1. 引用が http(s):// で始まると仮定します。
  2. ShowQuotation では、正規表現を使用してそのような文字列を識別します。不必要に複雑かもしれません。長さ 7 の部分文字列が であるか、長さhttp://8 の部分文字列がであるかを確認https://し、残りはすべて URL の一部であると想定します
  3. リンクにする
于 2012-04-15T23:07:44.587 に答える