[英]What's wrong with the array?
<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]
或head6.style.fontFamily = typeFont[3]
时都更改字体,并且该功能与head6.style.fontFamily = typeFont[3]
但它与数组无关。
由于Math.random
是一个函数,因此无法解析为数字,因此您会得到NaN
。
你必须打电话给功能
Math.floor( Math.random() * 10 )
请注意,只要数组具有恰好10个索引,就可以了,但是您通常希望使用数组长度而不是10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.