【第22期】观点:IT 行业加班,到底有没有价值?

用js在前台及后台生成随机字符串

原创 2016年06月02日 12:51:24

用js在前台生成随机字符串

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>随机密码生成器 - 随机字符串生成器 - Random Password Generator | C7TOOL</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" />
<meta name="description" content="随机密码生成器 - 随机字符串生成器 - Random Password Generator" />


<link rel="stylesheet" href="http://cdn.bootcss.com/pure/0.4.2/pure-min.css">
<link rel="stylesheet" href="../style.css">


<style>
#header {
    max-width: 800px;
margin-left:130px;
}
#main {
    max-width: 500px;
margin-left:130px;
}


ul {
    margin: 0;
    padding: 0;
    border-top: 1px solid #eee;
    list-style: none;
    font-size: 14px;
}


li {
    clear: both;
    overflow: hidden;
    padding: .5em 0;
    border-bottom: 1px solid #eee;
}


.pure-form label {
    display: block;
    overflow: hidden;
    margin: 0;
}


.pure-form span {
    float: left;
    margin: 6px 0;
}


input {
    float: right;
    margin-top: 9px;
}


#password_length,#password_quantity {
    margin-top: 0;
    width: 5em;
}


#generate {
    margin: 1em 0;
}


#output {
font-family: Monaco, Menlo, Consolas, Inconsolata, 'Deja Vu Sans Mono', 'Droid Sans Mono', 'Lucida Console', 'Courier New', Courier, monospace;
}
</style>
</head>
<body> 
<div id="header">
    <h1>随机密码生成器 - 随机字符串生成器</h1>
    <h2>Random Password Generator</h2>
</div>


<div id="main" class="pure-form">
<ul>
<li><label><input type="checkbox" id="include_number" checked /><span>数字</span></label></li>
<li><label><input type="checkbox" id="include_lowercaseletters" checked /><span>小写字母</span></label></li>
<li><label><input type="checkbox" id="include_uppercaseletters" checked /><span>大写字母</span></label></li>
<li><label><input type="checkbox" id="include_punctuation" /><span>标点符号</span></label></li>
<li><label><input type="checkbox" id="password_unique" /><span>字符不重复</span></label></li>
<li><label><span>密码长度</span><input type="number" id="password_length" min="0" value="8" /></label></li>
<li><label><span>密码数量</span><input type="number" id="password_quantity" min="0" value="1" /></label></li>
</ul>
<button id="generate" class="pure-button pure-button-primary pure-input-1">生成密码</button>
<textarea id="output" class="pure-input-1" cols="40" rows="7" readonly></textarea>
</div>


<script>
var $ = function(s){return document.getElementById(s)},
$includeNumber = $("include_number"),
$includeLowercaseletters = $("include_lowercaseletters"),
$includeUppercaseletters = $("include_uppercaseletters"),
$includePunctuation = $("include_punctuation"),
$passwordUnique = $("password_unique"),
$passwordLength = $("password_length"),
$passwordQuantity = $("password_quantity"),
$generate = $("generate"),
$output = $("output");


function rand(max) {
    return Math.floor(Math.random() * max);
};


$generate.onclick = function () {
    var chars = "";


    if ($includeNumber.checked) chars += "0123456789";
    if ($includeLowercaseletters.checked) chars += "abcdefghijklmnopqrstuvwxyz";
    if ($includeUppercaseletters.checked) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if ($includePunctuation.checked) chars += "`~!@#$%^&*()-_=+[{]}\|;:'\",<.>/?";


    var passwords = [],
passwordUnique = $passwordUnique.checked;
    for (var i = 0, l = $passwordQuantity.value; i < l; i++) {
        var _chars = chars.split(""),
password = "";
        for (var j = 0, k = $passwordLength.value; j < k; j++) {
            if (_chars.length < 1) break;
            var index = rand(_chars.length);
            password += _chars[index];
            if (passwordUnique) _chars.splice(index, 1);
        };
        passwords.push(password);
    };
    $output.value = passwords.join("\n");
};


$output.onfocus = function () {
    this.select();
}
</script>


</body>
</html>

用js在后台生成随机字符串


<%@ LANGUAGE='JAVASCRIPT' %>
<%
function rand(max) {
    return Math.floor(Math.random() * max);
};


function getRand(includeNumber,includeLowercaseletters,includeUppercaseletters,includePunctuation,passwordUnique,passwordQuantity,passwordLength)
{
    var chars = "";


    if (includeNumber) chars += "0123456789";
    if (includeLowercaseletters) chars += "abcdefghijklmnopqrstuvwxyz";
    if (includeUppercaseletters) chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if (includePunctuation) chars += "`~!@#$%^&*()-_=+[{]}\|;:'\",<.>/?";


    var passwords = [] ;
    for (var i = 0, l = passwordQuantity; i < l; i++) {
        var _chars = chars.split(""),
password = "";
        for (var j = 0, k = passwordLength; j < k; j++) {
            if (_chars.length < 1) break;
            var index = rand(_chars.length);
            password += _chars[index];
            if (passwordUnique) _chars.splice(index, 1);
        };
        passwords.push(password);
    };
    return passwords.join("<br/>");
}


Response.Write(getRand(1,1,1,1,1,8,12));
%>



版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

js随机调取图片

html5测试 window.onload=function (){ o.imgRandom(); } var o={ aImg:['5461d1a43dfae95c...

Js实现多张图片有规律的随机切换

多张图片随机切换   //初始化图片地址,用数组来标识多张图片   var pics = new Array("0.jpg","1.jpg","2.jpg","3.jpg");   /*   ...

程序员升职加薪指南!还缺一个“证”!

CSDN出品,立即查看!

JS实现图片随机浮动效果

图片随机浮动游戏 //对DIV进行绝对定位 div{      position:absolute;     }   var floatimg=docum...

js 实现图片自动移动

function dianwo() {             var obj = document.getElementById('mydiv');             var x = ob...

网页中通过js修改img的src属性刷新图片时,图片缓存问题现象表述及问题解决

问题:上传一张图片,通过js更新src属性刷新图片使其即时显示时,                     当img的src当前的url与上次地址无变化时(只更改图片,名称不变,不同图片名称相同...

JS操作CSS随机改变网页背景实现思路

JS和CSS让页面每次刷新随机产生一张背景图,当然我的回答是可以的,下面是具体的实现思路,感兴趣的朋友可以参考下 今天有个朋友在weibo上问我可不可以用JS和CSS让页面每次刷新随机产生一张背...

网页中通过js修改img的src属性刷新图片时,图片缓存问题现象表述及问题解决

问题:上传一张图片,通过js更新src属性刷新图片使其即时显示时,当img的src当前的url与上次地址无变化时(只更改图片,名称不变,不同图片名称相同)图片不变化(仍显示原来的图片)但通过fireb...

用javascript实现来随机位置出现广告图片

太晚了,哈哈。今天有点神经,继续发表吧。 无标题文档 div{     position:absolute;     } ...

JS生成随机字符串

function randomString(len) {   len = len || 32;   var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprs...
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)