js把HTML转成对象,将js对象转换为html「建议收藏」

大家好,又见面了,我是你们的朋友风君子。

好的,我有一些JS通过URL从JSON中提取数据。 我知道想要将每个对象(author_name,rating,author_url)转换为js ID,所以我可以在html中调用该ID。将js对象转换为html

例如

这是我的JS代码到目前为止

function initMap() {

var service = new google.maps.places.PlacesService(map);

service.getDetails({

placeId: ‘123’

}, function(place, status) {

if (status === google.maps.places.PlacesServiceStatus.OK) {

for(var i=0; i <= place.reviews.length; i++) {

console.log(place.reviews[i]);

alert(place.reviews[i].author_name);

alert(place.reviews[i].rating);

alert(place.reviews[i].author_url);

alert(place.reviews[i].text);

alert(place.reviews[i].relative_time_description);

alert(place.reviews[i].profile_photo_url);

}

}

});

}

是什么让这些成HTML,所以我可以样式和页面各处使用的最佳方法?

+0

创建具有所需内容和’的append()的’li’元素’它给你的’ul’ –

+0

尼斯信息,由于生病尝试。喜欢 ? (place.reviews [i] .author_name)append(li)? –

+0

eval,innerHtml,http://stackoverflow.com/questions/11351135/create-ul-and-li-elements-in-javascript –

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注