在main_map.js您有:
// Insert the <div> into the body document.
document.body.appendChild(div);
這就是爲什麼它是一切後,產生的原因。
創建自己的div + id和appendChild()代替body標籤。 DEMO
var apme = document.getElementById('ap');
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = "200px";
div.style.height = "200px";
div.style.borderWidth = "1px";
div.style.borderColor = "#000";
div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
apme.appendChild(div);
現在,這個div被插入在div#AP內。這個div可以是你希望在你的標記中的任何地方。
<edit>
你做:
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = divWidth+"px";
div.style.height = divHeight+"px";
// div.style.borderWidth = "0px";
// div.style.borderColor = "#000";
// div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
document.body.appendChild(div);
var apme = document.getElementById('map');
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = "203px";
div.style.height = "306px";
div.style.borderWidth = "0px";
div.style.borderColor = "#000";
div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
apme.appendChild(div);
這使得2格用相同的ID,這是不是你找什麼:)。
您應該已經刪除了:
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = divWidth+"px";
div.style.height = divHeight+"px";
// div.style.borderWidth = "0px";
// div.style.borderColor = "#000";
// div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
document.body.appendChild(div);
並將其替換爲:
var apme = document.getElementById('map');
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = divWidth+"px";
div.style.height = divHeight+"px";
// Insert the <div> into the heml document.
apme.appendChild(div);
這樣做的工作。非常感謝你。我從來不會想到我自己的! – user2984710
現在我已經有了這個工作,我意識到腳本在頁面的底部推送了額外的空白空間 - 在你提出上述編輯之前,SVG地圖在哪裏。你有什麼想法可以解決這個問題嗎? – user2984710
@ user2984710我會編輯我的答案給你看。不要猶豫,給點或接受答案的方式 –