gpt4 book ai didi

javascript - 获取 jVectormap 的值。 getElementbyID 不起作用

转载 作者:行者123 更新时间:2023-11-28 05:01:54 35 4
gpt4 key购买 nike

我尝试在 jVectormap 中设置标记。我从数据库中获取内容并将其写入隐藏的输入字段中。按以下格式返回:

{latLng:[52.5200066,13.404954],name:'Berlin'},{latLng:[53.0792962,8.8016937],name:'Bremen'},{latLng:[49.8728253,8.6511929],name:'Darmstadt'},{latLng:[50.1109221,8.6821267],name:'Frankfurt'},{latLng:[53.5510846,9.9936818],name:'Hamburg'},{latLng:[54.3232927,10.1227652],name:'Kiel'},{latLng:[50.937531,6.9602786],name:'Köln'},{latLng:[48.30694,14.28583],name:'Linz'},{latLng:[48.1351253,11.5819806],name:'München'},{latLng:[53.6355022,11.4012499],name:'Schwerin'},{latLng:[48.7758459,9.1829321],name:'Stuttgart'},{latLng:[48.0689177,11.6212533],name:'Unterhaching'},,{latLng:[48.2081743,16.3738189],name:'Wien'},

如果我想阅读这个字段,什么也不会发生。如果我将此行复制并粘贴到 javascript 部分,一切都会很好。

这正在工作:

<script>
$(function(){
var map,
markers = [
{latLng:[52.5200066,13.404954],name:'Berlin'},{latLng:[53.0792962,8.8016937],name:'Bremen'},{latLng:[49.8728253,8.6511929],name:'Darmstadt'},{latLng:[50.1109221,8.6821267],name:'Frankfurt'},{latLng:[53.5510846,9.9936818],name:'Hamburg'},{latLng:[54.3232927,10.1227652],name:'Kiel'},{latLng:[50.937531,6.9602786],name:'Köln'},{latLng:[48.30694,14.28583],name:'Linz'},{latLng:[48.1351253,11.5819806],name:'München'},{latLng:[53.6355022,11.4012499],name:'Schwerin'},{latLng:[48.7758459,9.1829321],name:'Stuttgart'},{latLng:[48.0689177,11.6212533],name:'Unterhaching'},,{latLng:[48.2081743,16.3738189],name:'Wien'},

],

这不起作用:

$(function(){
var map,
markers = [
document.getElementById("geodata").value;

],

我的问题出在哪里? :(

最佳答案

输入中的值是 JSON 字符串,而不是对象,因此您必须将其解析为对象:

$(function(){
var map,
markers = [
JSON.parse(document.getElementById("geodata").value);

],

关于javascript - 获取 jVectormap 的值。 getElementbyID 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42084803/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com