我的网页应该打印出一串数字,但isn'

My webpage should be printing out a string of digits, but isn't

本文关键字:数字 一串 isn 网页 打印 我的      更新时间:2023-09-26

知道为什么下面的代码不能工作吗?它应该创建一个网页,只是一串数字(通过一个可逆的加密方案,你可以在函数encrypt()中看到)。然而,所发生的一切是document.write(encrypt("Yo, dawg, I heard you like functions"));被打印在网页的顶部。

<html>

<head>
    <title>Simple encrypt/decrypt</title>

    <script type="text/javascript">
        function encrypt(thisString)
        {
            retString = "";
            /* Make retString a string of the bit representations of 
               the ASCII values of its characters in order.
            */
            for (i = 0, j = thisString.length; i < j; i++) 
            { 
                bits = thisString.charCodeAt(i).toString(2);
                retString += new Array(8-bits.length+1).join('0') + bits;
            }
            /* Compress retString by taking each substring of 3, 4, ..., 9 
               consecutive 1's or 0's and it by the number of such consecutive
               characters followed by the character. 
               EXAMPLES:
                    "10101000010111" --> "10101401031"
                    "001100011111111111111" --> "0011319151"
            */
            retString.replace(/([01])'1{2,8}/g, function($0, $1) { return ($0.length + $1);});
            return retString;
        } 

    </script>
</head>
<body>
    <script="text/javascript">
        document.write(encrypt("Yo, dawg, I heard you like functions"));
    </script>
</body>
</html>

打字错误:

<script="text/javascript">
应该

<script type="text/javascript">