2013-12-08 51 views
0

我正在嘗試創建一個映射,其中有一個選項可以將名稱添加到dif中。街道。我的計劃是將這個功能包含在複選框和使用地圖信息中。帶有複選框和js的文本輸入

由於我對這些組件如何協同工作的理解有限,我打了一個靜止不動,這裏是我的非功能代碼:

<head> 
    <script> 
    var checkbox1 = document.getElementById("checkbox1"); 
    var posting = document.getElementById("post_location"); 

    function visVei(){ 
    if (checkbox1.checked){posting=" 
    <map name='kartet_info' style='cursor:help'> 
    <Area shape=poly coords=326, 463, 278, 103, 286, 101, 336, 464 onmouseover=writeText2('Prinsen Gate'); onmouseout=writeText2('');/></map>" 
    } 
    } 
    </script> 
</head> 

這應該也會寫到:

<span id="post_location" style="display:none;"></span> 

一次

<form action=""> 
<input type="checkbox" class="check_1" id="checkbox1" onchange="visVei();"><span class="in_check_1">Gatenavn</span></input> 
</form> 

是否託運了。

回答

0

試試這個

<script type="text/javascript"> 
var checkbox1 = document.getElementById("checkbox1"); 
var posting = document.getElementById("post_location"); 

function visVei(){ 
    if (checkbox1.checked){ 
     posting.innerHTML="<map name='kartet_info' style='cursor:help'><Area shape=poly coords=326, 463, 278,103, 286, 101, 336, 464 onmouseover=writeText2('Prinsen Gate'); onmouseout=writeText2('');/></map>"; 
     posting.style.display = "block"; 
    } 
} 
</script> 
+0

沒有,仍然沒有給出反饋,順便說一句,該網站不應該重裝一次一個複選框被選中,如果該事項? – Freshman

+0

我看到你使用onchange - 事件,一定要點擊複選框後按Tab鍵。我不希望將它綁定到onclick事件 – N0lf

+0

O並將您的腳本塊移動到頁面末尾,現在getDocumentById可能會失敗,因爲DOM尚未準備好 – N0lf

相關問題