访客进入网站的时候,按照30%的概率执行Ajs代码,否则不执行,直接打开网页.这个该怎么写?

解决方案 »

  1.   

    用随机数
      function test()
      {
        var num=parseInt(Math.random()*10);
        if(num==1 || num==2 || num==3)
        {
          alert(num);//这儿代码有30%机率执行
        }
      }
      

  2.   

    要不这样子:
    <script>if(Math.floor(Math.random()*3)==0){alert('30%')}</script>
      

  3.   

    <script>if(Math.floor(Math.random()*3)==0){src='js.js'}</script>
    这样?
      

  4.   

    if(parseInt(Math.random()*3)==1){
        code
    }
      

  5.   

    http://topic.csdn.net/u/20110915/19/7fe21a90-98cd-4993-a102-af12e2907594.html
      

  6.   

    if((Math.random()*100)<=30){
    dosomething....
    }