开发者

button with random function jqt

i'm an absolute beginner - so after days of searching i'm asking for help: i have a small web app in jqtouch an want the user to be able to tap on an i开发者_如何学JAVAmage = button, which jumps to a randomly chosen id = page.

how am i doing this? something like this is not working:

header:

var randomlinks=new Array()

randomlinks[0]="page100"
randomlinks[1]="page120"
randomlinks[1]="page130"

function randomlink(){
document.location='#' + randomlinks[Math.floor(Math.random()*randomlinks.length)]
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

body:

<a href="#" class="dissolve"><img src="images/randombutton.png" class="something" onClick="MM_callJS('randomlink()')"></a>

thanks a lot for your help.


you could do:

var randomlinks=[];

randomlinks[0]="page100"
randomlinks[1]="page120"
randomlinks[2]="page130"

function randomlink(){
 var idx = Math.floor(Math.random()*randomlinks.length);
 window.location.href ='#' + randomlinks[idx];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜