這可能很容易做到,但是自從我上次使用JavaScript以來已經有相當長的一段時間了,我不能爲我的生活記住如何做到這一點(是的,我先搜索了,但沒有發現任何可以幫助我)。渲染陣列數據
基本上我想用一個函數來渲染這是一個HTML的博客文章:
<html>
<head>
<style>
body
{
background-color:#ffa500;
}
#blogElement
{
background-color: #fff;
margin-left:auto;
margin-right:auto;
width:70%;
}
</style>
</head>
<body>
<div id="mainContent">
<div id="blogElement"></div>
</div>
<script>
var myBlogPosting = {
title: "Google launches underwater Street View",
image: "1.jpg",
author: "Xeni Jardin",
bodyText: "<p>Today Google Maps unveils a new Street View feature: " +
"underwater panoramic views of six special sea spots. " +
"The idea is to create a virtual map of the oceans, " +
"documenting the state of fragile ecosystems as they " +
"change over time, and sharing a vivid experience of " +
"part of our world that few humans get to see up close " +
"and in person, in real life.</p>" +
"<p>The ocean collection on Google Street View is now " +
"available at maps.google.com/ocean, and includes coral " +
"reefs and the creatures who live in them, in Australia, " +
"the Philippines and Hawaii.</p>",
link: "http://boingboing.net/2012/09/25/google-launches-underwater-str.html",
ranking: "3",
}
function CreateBlogHtml(blogpost)
{
return "<h1>"+blogpost.title+"</h1>"+
"<img src="+blogpost.image+" />"+
"<p>Author: "+blogpost.author+"</p>"+
blogpost.bodyText+
"<a href=\""+blogpost.link+"\">Read more</a>"+
"<p>Ranking: "+blogpost.ranking+"</p>";
}
document.write(CreateBlogHtml(myBlogPosting));
</script>
</body>
</html>
這可能是這些東西,我會拍自己的臉瞬間就到我這裏來一個
啊,看,我知道這將是一個相對簡單的事情!謝謝! – Cleverbird
也許愚蠢的問題......但我如何將CSS效果應用到這些元素?我試圖給blogElement添加一些簡單的效果,但似乎瀏覽器會忽略這些效果。還嘗試向容器DIV添加效果,但同樣,瀏覽器似乎忽略了這些效果。 – Cleverbird
你是什麼意思,你的意思是CSS樣式或動畫效果? –