【发布时间】:2015-09-01 02:26:48
【问题描述】:
我正在尝试让页面重新加载,并在每个部分中显示不同的消息。我以为我已经完美了,但无法弄清楚为什么它没有准确显示。
这里是代码
HTML
<div id="words"></div>
这里是 Javascript
var words = new Array();
words[0] = " loves you";
words[1] = "Would you like to tuck you in?";
words[2] = " is here for you";
words[3] = "Did you know that can be in 2 places at once?";
var random = Math.ceil (Math.random()*words.length) - 1;
$('words').set('html', words[random]);
【问题讨论】:
-
你没有包括 jQuery,猜测。或者您打算使用的任何库,它使用
$作为别名。而且,如果你正在使用jQuery,你应该使用$('#words');但是我之前没有遇到过set()这个方法,那是插件吗? -
我不是有意识地使用插件。我认为 $ 符号通常也用于 jquery。我尝试添加一些cdn,但它仍然没有任何帮助。我从另一个关于如何在线这样做的建议中检索了代码
标签: javascript html random messages