1. 程式人生 > >HTML input文字框賦值隨機字串 JS指令碼

HTML input文字框賦值隨機字串 JS指令碼

<input type="text" id="sj" name="way" class="am-form-field am-radius" required="required" placeholder="例如:6324upup" readonly />
<script>
    window.onload = random_A;
    function random_A() {
        let str = '';
        for(let i = 1;i<=8;i++){
            str = str +String.fromCharCode(Math.floor(Math.random()*24+65));
        }
        
		document.getElementById("sj").value = [0].innerText = str;
    }
	
</script>