0
4

3 に答える 3

0

http://jsbin.com/asedoj/1/edit

インライン JS は使用しないでください。保守が困難です。
任意の範囲で乱数を生成する関数を作成します。

<a id="detecteur-play">Play</a>

<a style="display:none;" id="ID1">STOP1</a>
<a style="display:none;" id="ID2">STOP2</a>

// Reusable Randomizer function
function ran(min, max) {
  return ~~(Math.random()*(max-min+1))+min;
}

$('#detecteur-play').click(function(){
  $(this).hide();
  $('#ID'+ran(1,2)).show();
});

私が使用した ~~ 演算子は二重の NOT ビット演算子であり、置換に使用されます。Math.floor

于 2013-07-28T20:42:14.047 に答える
0

このデモを試してください: http://jsfiddle.net/txGuu/8/

var r = Math.floor(Math.random() * 2) + 1;
$("#ID"+r).show();
于 2013-07-28T20:32:38.863 に答える