如何使HTML按钮的onclick事件随机触发两个不同的函数之一?

How do I make an HTML button’s onclick event trigger one of two different functions at random?

I’m using PHP on the server, and jQuery on the client. Using this code when i click the button image nothing happens...

function a(){  
    alert('A got called!');
}

function b(){  
    alert('B got called!');  
}  

$('#button').bind('click', function(){  
    var rnd = Math.floor(Math.random() * 2);  
    if(rnd)  
       a();  
    else  
       b();  
});

.........

< "base_url().'images/free.png';" rel="nofollow" border='0' align='center' alt="FREE"  id="button"   />
查看全部
dongmouhao7438
dongmouhao7438
2010/07/24 10:55
  • button
  • random
  • php
  • html
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

5个回复