在 JS 中随机生成带有 url 的自定义文本

Random generate custom text with url in JS

本文关键字:url 自定义 文本 JS 随机      更新时间:2023-09-26

我从列表中找到了这个javascript随机文本生成器

var quotes=new Array();
quotes[0] = "text1";
quotes[1] = "Text2";
quotes[2] = "text3";
quotes[3] = "text4";
var q = quotes.length;
var whichquote=Math.round(Math.random()*(q-1));
function showquote(){document.write(quotes[whichquote]);}
showquote();

和 html:

<script language="javascript" type="text/javascript" src="quotes.js"></script>

所以,它工作得很好,但是...我希望生成的每个文本都有指定的网址,例如<a href="#">

谢谢!

就我所能得到你需要的,这可能会完成这项工作:

function showquote(){document.write('<a href="#">' + quotes[whichquote] + '</a>');}