代码如下
<!DOCTYPE HTML> <html> <head> <script type="text/javascript" src="../jquery-1.7.1.min.js"></script> </head> <body> <!-- <div style="200px;height100px;background-color:#ccc;color:red;">¶¹¸¯¸ÉËêµÄ·¨¹úµçÊÓ¸²¸Ç</div> <script type="text/javascript" src="http://www.yirendai.com/posterpic/126.js"></script> --> <!-- <select> <option>测试下拉</option> <option>测试下拉</option> <option>测试下拉</option> </select> <button>点击</button> <script> $(function(){ $('button').click(function(){ $('select').trigger('click'); }); }) $('select').click(function(){ console.log(1); }); </script> --> <button id="tourl">产生</button> <p id="strinfo"> </p> <script type="text/javascript"> var urlList = [ 'http://www.baidu.com', 'http://www.sina.com', 'http://www.163.com', 'http://www.qq.com' ]; var strinfo; var tourlEle = document.getElementById('tourl'); strinfo = document.getElementById('strinfo'); tourlEle.onclick=function(){ var k = getToUrl(urlList,100000); } function getToUrl (urlList, maxNum) { var resKey = 0; if (urlList.length <= 0) { resKey = 0; } maxNum = maxNum ? maxNum : 10000; var keyList = []; var resKey = 0; var step = Math.ceil(maxNum/urlList.length); var key = Math.ceil(Math.random()*maxNum); for (var i=0; i < urlList.length; i++) { keyList[i] = step*(i+1); } for (var i = 0; i < keyList.length; i++) { if (key <= keyList[i]) { resKey = i; break; } } return resKey; } </script> </body> </html>