如何将这个Javascript加载到我的blogspot页面?

时间:2012-07-18 10:02:41

标签: blogger

美好的一天!

新手在这里我发现谷歌中的这个Javascript我不知道如何将结果插入我的新博文。我想在新博客帖子中显示随机文本

<script type="text/javascript">
<!--
//I. Array of banner that will randomly appear

var randomquote = new Array ( );
randomquote[0] = '<em>Allergic reactions</em>';
randomquote[1] = '<em>Dental hygiene </em>';
randomquote[2] = '<em>Diabetes</em>';
randomquote[3] = '<em>Back pain</em>';
randomquote[4] = '<em>Weight loss </em>';
randomquote[5] = '<em>Heat cramps</em>';
randomquote[6] = '<em>Heat stroke</em>';
randomquote[7] = '<em>Pain Medication </em>';
randomquote[8] = '<em>Diet plan</em>';
randomquote[9] = '<em>Dehydration</em>';

//II. function to generate number from 0 to n

function randomzero (n)
{
  return ( Math.floor ( Math.random ( )*0.9999999999999999* (n + 1)) );
}

//III. assign any random number from 0 to 2 to x.

x = randomzero(2);

//IV. display the text 

document.write(randomquote[x]);
//-->

</script>

提前感谢。

1 个答案:

答案 0 :(得分:4)

这很容易。我已经在博客中尝试过并且工作正常。

  1. 打开您的博客
  2. 创建新帖子
  3. 使用HTML模式并粘贴上述代码
  4. 保存您的帖子并检查您的HTML代码是否仍然相同(我试过博客最后更改了一些内容)。
  5. 预览您的帖子,您会看到过敏反应
  6. 等文字
  7. 关闭预览并再次预览您的帖子,现在文本会有所不同,例如 Diabetes
  8. 您可以在javascript之前和之后添加任何文本(当然使用HTML格式)

相关问题