存储html内容时,json和js是否需要不同的html语法?
例如此处:以下js对象中的'
和+
。我的数据是在json数组中,但似乎略有不同。
我只熟悉在HTML文档中使用html数据,并且很难找到关于这些基本内容的信息。
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park.</p>'
'</div>'+
'</div>';
&#13;
答案 0 :(得分:-1)
对于最佳做法,您可以从DOM中存在的template
标记中获取HTML代码,例如:
var contentString = $('#mydiv').html(); //with jquery
或
var contentString = document.getElementById('mydiv').innerHTML; //with vanilla javascript
template
应该有你的infowindow模板,如下所示:
<template id="myDiv">
<div id="content">
<!-- your infowindow html code goes here -->
</div>
</template>
为什么template
代码?因为它会为用户隐藏。如果您愿意,可以使用div
标签或任何隐藏样式的标签。