我希望能够根据选中的复选框更改var chars
。
现在,我正在寻找一些复选框是否已经检查过,但是当我尝试它时,密码就会出现空白。
JS代码
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz=-][';/.,`~!@#$%^&*()_+|}{:?><";
var string_length = 10;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
if($('#checkbox1').is(':checked')){
var lowstring = randomstring.toLowerCase();
document.randform.randomfield.value = lowstring;
} else {
document.randform.randomfield.value = randomstring;
}
// document.randform.randomfield.value = randomstring; //
}
Html代码
<div class="preference">
<div class="form2">
<div class="wanted"> <!-- Toggle Special Characters -->
<label class="input-toggle">
<input type="checkbox" id="checkbox1" checked>
<span></span>
</label>
<p>Toggle Special Characters</p>
<div class="wanted"> <!-- Toggle Numbers -->
<label class="input-toggle">
<input type="checkbox" checked>
<span></span>
</label>
<p>Toggle Numbers</p>
<div class="wanted"> <!-- Toggle Uppercase -->
<label class="input-toggle">
<input type="checkbox" checked>
<span></span>
</label>
<p>Toggle Uppercase</p>
<div class="wanted"> <!-- Toggle Lowercase -->
<label class="input-toggle">
<input type="checkbox" checked>
<span></span>
</label>
<p>Toggle Lowercase</p>
</div>
</div>
</div>
</div>
</div>
</div>