这是有关的div:
<div id="map" class="map" data-settings="map-settings.json"></div>
map-settings.json:
{
"mapZoom": 15,
"markerAddress": "881 7th Ave New York",
"offsetX": 100,
"offsetY": 10,
"markerImagePath": "assets/img/marker-21x32.png",
"markerLatLng": [
40.7652577,
-73.9798788
]}
我想把JSON文件放在“data-settings”属性中,我试过这个:
<div id="map" class="map" data-settings='{
"mapZoom": 15,
"markerAddress": "881 7th Ave New York",
"offsetX": 100,
"offsetY": 10,
"markerImagePath": "assets/img/marker-21x32.png",
"markerLatLng": [
40.7652577,
-73.9798788
]}'></div>
但是不要工作!
任何帮助?
答案 0 :(得分:0)
确实如此;您所要做的就是像
一样访问它var myMap = document.getElementById("map"),
mySettings = JSON.parse(myMap.dataset.settings);