我試圖以編程方式將文章添加到我的網站,然後將隨機單詞添加到使用jquery的每篇文章。我能夠製作所有文章,但我無法向文章添加文字。這裏是我的代碼: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>
有你檢查了jQuery lorem插件是否正確加載到您的網頁? – Carl
是的,它的工作原理。可以說我有一個
它會在正文中顯示一個單詞。 – user977154用你的代碼看這個小提琴。工作得很好。 小提琴 - http://jsfiddle.net/dVVHs/1/ – Jeff