我目前正在尝试开发一个随机重定向按钮,我需要对以下代码进行两处调整:
<script>
<!--
/*
Random link button- By JavaScript Kit (http://javascriptkit.com)
Over 300+ free scripts!
This credit MUST stay intact for use
*/
//specify random links below. You can have as many as you want
var randomlinks=new Array()
randomlinks[0]="http://surveymonkey.com"
randomlinks[1]="http://typeform.com"
randomlinks[2]="http://dynamicdrive.com"
randomlinks[3]="http://cnn.com"
randomlinks[4]="http://www.geocities.com"
function randomlink(){
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
}
//-->
</script>
<form method="post">
<p><input type="button" name="B1" value="Continue" onclick="randomlink()"></p> </form>
上面的代码生成了一个按钮,在已发布的网站上单击该按钮似乎没有任何反应。如何使按钮真正 重定向?我还想将按钮的大小调整为大 5 倍并居中对齐。
感谢您的帮助。
最佳答案
它无法打开的原因是您的函数中使用了 .open
方法。
下面是使用 window.open
的新代码:
window.open(randomlinks[Math.floor(Math.random()*randomlinks.length)]);
要格式化按钮,您应该使用 CSS。
查看类似 this 的内容
关于javascript - 我如何调整此代码以在 Google 协作平台上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48930545/