【发布时间】:2022-08-14 17:18:57
【问题描述】:
我无法设置变量:
<input type=\"text\" id=\"routeprofile\"><button onclick=\"profileFunction()\">Choisir</button><p id=\"profile\"></p>
的JavaScript:
var routingprofile;
function profileFunction() {
const routingprofile = document.getElementById(profile);
alert(\"Value after trigger:\" + routingprofile)
} ;
结果是:空。
我希望它在使用时全局可用:
L.Routing.control({
router: osrRouter,
position: \'topleft\',
collapsible: true,
profile: routingprofile,
geocoder: L.Control.Geocoder.nominatim({})
// }),
}).addTo(map);
-
const routingprofile = document.getElementById(profile);你的意思是在这里使用字符串吗?还是profile在某处定义?如果是前者,那么getElementById(\"profile\"); -
document.getElementById(\'profile\'); // <-- missing quotes in argument. -
@pilchard 我想使用 id=\"routeprofile\" 文本框的内容,它是一个文本字符串
标签: javascript