我想隨機鏈接到任何頁面x,這是我寫的代碼,迄今爲止,它不工作...任何建議?做一個動態鏈接,改變頁面引用
var page1link = "pages/sketches.php";
var page2link = "pages/photography.php";
var page3link = "pages/defined.php";
var page4link = "pages/spectacle2.php";
var list = [page1link, page2link,page3link, page4link];
var number = list[Math.floor(Math.random()*list.length)];
var randomlink =list[number];
function myFunction(){
document.getElementById("mylink").href = 'randomlink';
};
<body onload="myFunction()">
<container>
<h1>
<a href='randomlink' id='mylink'> Click Me</a>
</h1>
</container>
</body>
有你'聲明隨時隨地randomizer'?如果是這樣,它有什麼作用? –
''randomlink'!== randomlink'除非'randomlink ='randomlink';' – epascarello
Javascript數組沒有size()方法。 – nnnnnn