2013-12-08 49 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

相关问题