我正在尝试以编程方式将文章添加到我的网站,然后使用Jquery为每篇文章添加一个随机单词。我能够制作所有文章,但我无法在文章中添加文字。这是我的代码:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-2.1.0.min.js" type="text/javascript"></script>
<script src="Script/jquery.lorem.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function ()
{
var colors = ["#CCCCCC", "#333333", "#990099"];
var rand = Math.floor(Math.random() * colors.length);
$(function () {
for (var i = 0; i < Math.floor((Math.random() * 64) + 34) ; i++) {
$("#Inferface").append("<article class='box' style='background-color:" + colors[rand] + "'><span>" + i + "</span>");
}
});
// This line below should be adding the random word to each of the articles
$('.box').lorem({ type: 'words', amount: '1', ptags: false });
});
</script>
</head>
<body id="Inferface">
</body>
</html>
答案 0 :(得分:1)
奇怪,在我看来,代码正在进行很少的调整
$(function ()
{
var colors = ["#CCCCCC", "#333333", "#990099"];
var rand = Math.floor(Math.random() * colors.length);
for (var i = 0; i < Math.floor((Math.random() * 64) + 34) ; i++)
{
$("#Interface").append("<article class='box' style='background-color:" + colors[rand] + "'><span>" + i + "</span>");
}
// This line below should be adding the random word to each of the articles
$('.box').lorem({ type: 'words', amount: '1', ptags: false});
});
..你可以在这里查看: Working Example