<input type="button" id = "text_num"/>
<input type="button" id="txt_btn" />
    <input type="text" id="txt_num" />

    <script type="text/javascript">
        var time = new Date().getTime();
        document.getElementById("text_num").value = time.toString().substr(time.toString().length - 4, 4);
        function getNum() {
            if (document.getElementById("txt_num").value == document.getElementById("text_num").value)
                alert("验证码正确");
            else
                alert("验证码不正确");
        }
    </script>