【发布时间】:2016-02-09 23:44:03
【问题描述】:
我正在尝试使用 JQuery 通过 corechart 获得一些图形功能,但是一旦加载了可视化 API,我就无法获得任何文档元素。下面是我的示例:
$(document).ready(function() {
if ($("#myId").length > 0) {
google.load("visualization", "1.1", {
packages: ["corechart"]
});
google.setOnLoadCallback(function() {
if ($("#myId").length > 0) {
alert("Found a match!!");
}else{
alert("Not found!!");
}
});
}
});
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
</head>
<body>
<h1>Hello Plunker!</h1>
<div id="myId">Hello from Div!!</div>
</body>
</html>
我希望执行 if 块中的警报。我仅在检查 #myId 但在回调中丢失(而不是所有 html 元素)之后才加载可视化包。请指教
【问题讨论】:
-
加载 google 库的类似,杀死文档元素及其下的所有内容,检查 google.load("visualization" 的行为
标签: jquery charts google-visualization