阵列出了什么问题?

时间:2015-03-01 07:33:51

标签: javascript arrays string

<html>

<head>

    <title> Random </title>

    <script type="text/javascript" language="JavaScript">

        var typeFont = new Array ( "cooper","Fixedsys","Edwardian Script ITC", "Gill Sans MT", "Kozuka Gothic Pro", "Lucida Sans", "Adobe Gothic Std", "Adobe Naskh", "Algerian","Arial Unicode MS");

        function font()
        {
            head6.style.fontFamily = typeFont[ Math.floor( Math.random * 10 ) ];
        }
    </script>
</head>

<body>

    <center>
        <h1 onmouseover="font()" onmouseout="font" id="head6" > this is the text </h1>
    </center>

</body>

我试图在每次鼠标翻转或关闭时更改字体,并且此功能使用head6.style.fontFamily = typeFont[3],但它不与数组一起使用。

1 个答案:

答案 0 :(得分:3)

NaN因为Math.random是一个功能而无法解析为某个数字。

你必须打电话给

Math.floor( Math.random() * 10 ) 

请注意,只要数组有10个索引就可以了,但您通常希望使用数组长度而不是10

相关问题