每次刷新页面时,如何为一行文本生成随机字体? [英] How do I generate a random font to a line of text every time page is refreshed?
问题描述
< script>
var fontType = [Arial,Verdana,Helvetica];
var num;
num = Math.floor(Math.random()* 3);
document.getElementById(fontfamily)。src = fontType [num];
< / script>
这似乎不起作用。我想知道我将不得不打电话给字体的ID,但是甚至有GetelementById(fontfamily)这样的东西?这也是在我的身体标签。
var font = [];
font [0] =Times New Roman;
font [1] =Arial;
font [2] =Helvetica;
这会是更好的选择吗?我如何得到这个随机选择?
您想要 每当你想使用JavaScript来设计一个元素的样式时,使用 I am trying to generate a new font every time my page is refreshed from a list in my JavaScript. I want 4 fonts total, and I want the line that reads "Font" to be the font that actually changes. I can't get the font to change at all anytime I refresh the page. Any way I can possibly do that with JavaScript? Here are some things I tried: This didn't seem to work. I wondered I'd have to call an ID for the fonts, but is there even such a thing as "GetelementById(fontfamily)"? This was also in my body tags. Would this be a better option? How would I get this to randomly choose? You want Whenever you want to style an element using JavaScript, use 这篇关于每次刷新页面时,如何为一行文本生成随机字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! document.getElementById(fontfamily)。style.fontFamily; $ c
.style
,然后将css属性赋值。所以 font-family
变成 fontFamily
, background-image
变成 backgroundImage
var fontType = [Arial,Verdana, 黑体];
var num;
num = Math.floor(Math.random()* 3);
document.getElementById(fontfamily)。style.fontFamily = fontType [num];
<script>
var fontType = [ "Arial", "Verdana", "Helvetica"];
var num;
num=Math.floor(Math.random()*3);
document.getElementById("fontfamily").src=fontType[num];
</script>
var font = [];
font[0] = "Times New Roman";
font[1] = "Arial";
font[2] = "Helvetica";
document.getElementById("fontfamily").style.fontFamily;
.style
then camelcase the css attribute. so font-family
becomes fontFamily
, background-image
becomes backgroundImage
var fontType = [ "Arial", "Verdana", "Helvetica"];
var num;
num=Math.floor(Math.random()*3);
document.getElementById("fontfamily").style.fontFamily =fontType[num];