python - javascript无法访问dom
问题描述
我有这段代码可以在 vanilla js 中使用,但在 Flask 模板引擎中不起作用。
在基本的 HTML-JS 中它没有任何问题,但不知何故我认为我在 Flask 中遗漏了一些东西。有什么我错过的吗?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
{% extends 'layout.html' %}
{% block content %}
<body>
<div id="map"></div>
<script type="text/javascript">
function initMap(){
let map = new google.maps.Map(document.getElementById("map"), {
center: { lat: -8.6478, lng: 115.1385 },
zoom: 14,
});
alert("from initmap");
var pointOfInterest = [
{
position: {lat: -8.6595, lng: 115.1301},
price : '1000000',
},
{
position:{lat: -8.654355373797795, lng: 115.12441781895892},
price: '49999999'
}
]
pointOfInterest.map(prop =>{
console.log(prop);
})
}
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=[redacted]&callback=initMap&v=weekly"
async
></script>
</body>
{% endblock content %}
</html>
api 键没有任何问题,但我无法在 div 中显示谷歌地图。
解决方案
推荐阅读
- jquery - 应用 jQuery 选择器 [attribute*=value] 并遍历点击功能
- python - 使用 tkinter Canvas 显示图像,然后使用 cv2.circle/cv2.line 在图像上绘图
- rust - 模式匹配如何与 Rust 中的 ref 一起工作?
- python - numpy.diff 产生意想不到的结果
- bash - 更改 USER 后如何以 root 身份运行 docker CMD
- python - 如果交易在烧瓶中成功,则条带不会保存
- azure-cosmosdb - java sdk的cosmos sql api中的upsertItem中是否有ParitionKey输入?
- php - 语法错误,意外 ')',期待 '['
- google-tag-manager - 在 GTM 中向 Google Ads 转化代码添加自定义字段
- javascript - JS中检测手机角度(0、90、-90、180)的方法