我正在尝试从列表中调用javascript单词并将其放在html链接中。 像这样,但它不起作用。:
<a href="http://wikipedia.org/wiki/<"class="type>">
Read more
</a>
我想在链接中使用其中一个单词(我将其设置为随机)
var game = {
type : ['One', 'Two', 'Three', ],
function idea(el) {
var i = el.length,
j,
temp;
if ( i == 0 )
return;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = el[i];
el[i] =el[j];
el[j] = temp;
}
return el[0];
}
答案 0 :(得分:1)
这样的事情应该有效:
var game = {
type: ['One', 'Two', 'Three']
}
function getRandom(t, el) {
el.href += game[t][Math.floor(Math.random() * game[t].length)];
}
<a href="http://wikipedia.org/wiki/" onclick="getRandom('type', this)">
Read more
</a>