js简单字母验证码


<html lang="en">
<head>
    <script type="text/javascript">
        function createCode() {
            var datas = ['A','B','C','D','E','F'];
            var code = "";
            for(var i = 0;i < 4;i++){
                var index = Math.floor(Math.random()*datas.length);
                code += datas[index];
            }

            var spanNode = document.getElementById("code");
            spanNode.innerHTML = code;
        }

        function ready() {
            createCode();
        }

    script>

    <meta charset="UTF-8">
    <title>产生验证码title>
head>
<body onload="ready()">
    <span id="code">span><a href="#" onclick="createCode()">看不清,换一个a>
body>
html>

重点:
1.onload,在js里面写一个function ready(),然后调用
防止找不到,因为刚开始运行时,无法找到id code
2.看不清,换一个这句就是span里面不放东西,可以后来再放进去

你可能感兴趣的:(js简单字母验证码)