我试图使用java脚本制作函数图层,这是代码:
$(document).ready(function(){
function changeLayer(idSelections)
{
if (idSelections === "Agro Industri")
{
if (document.getElementById("AI").checked === true)
{
if(AI.getMap() === null)
{
AI.setMap(map);
}
}
if (document.getElementById("AI").checked === false)
{
AI.setMap(null); // layer set off
}
}
};
});这是HTML:
<body>
<div class="row">
<input type="checkbox" name="Agro Industri" value="Agro Industri" id="AI" onClick="changeLayer(this.value)"> Layer AI<br/>
</div>
<script src="js/scripts.js"></script>
</body>但是,每次我试图选中/取消复选框,我总是得到这个错误Uncaught ReferenceError: changeLayer is not defined。有人能帮忙纠正这个错误吗?
发布于 2015-04-30 07:19:30
把函数放在文件外面准备好。文档准备中的脚本将在DOM完成呈现到页面后运行。
<script>
function changeLayer(idSelections)
{
if (idSelections === "Agro Industri")
{
if (document.getElementById("AI").checked === true)
{
if(AI.getMap() === null)
{
AI.setMap(map);
}
}
if (document.getElementById("AI").checked === false)
{
AI.setMap(null); // layer set off
}
}
};
</script>https://stackoverflow.com/questions/29961411
复制相似问题