一个简单的jquery随机数生成代码。
实现如下功能:
代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery生成多组随机数-www.jbxue.com</title>
<style>ul{list-style:decimal;}</style>
<script src="/js/jquery-latest.js"></script>
</head>
<body>
<input type="button" value="Test" id="Test" />
<script>
var a = {};
$('#Test').on('click', function(){
$('<ul>' + new Array(8).join(' ').replace(/ /g, function(){var b; while(true){b = Math.random().toString().substr(2, 7)/100; if(b.toString().length === 8 && a[b] === undefined){return '<li>' + (a[b] = b) + '</li>';}}}) + '</ul>').appendTo('body');
});
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery生成多组随机数-www.jbxue.com</title>
<style>ul{list-style:decimal;}</style>
<script src="/js/jquery-latest.js"></script>
</head>
<body>
<input type="button" value="Test" id="Test" />
<script>
var a = {};
$('#Test').on('click', function(){
$('<ul>' + new Array(8).join(' ').replace(/ /g, function(){var b; while(true){b = Math.random().toString().substr(2, 7)/100; if(b.toString().length === 8 && a[b] === undefined){return '<li>' + (a[b] = b) + '</li>';}}}) + '</ul>').appendTo('body');
});
</script>
</body>
</html>