gpt4 book ai didi

javascript - 渲染一些 JSON 后,我的 javascript 的第二部分没有执行

转载 作者:行者123 更新时间:2023-11-28 21:17:47 25 4
gpt4 key购买 nike

嘿伙计们,我想知道为什么这个文件中的最后一个脚本不起作用 - 它假设获取从 JSON 中提取的值并将其与设定值进行比较。感谢大家的帮助!

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {

var url = "https://graph.facebook.com/tenniswarehouse?callback=?";


$.getJSON(url,function(json){
var html = "<div id=\"tester\">" + json.likes + "</div>";
//A little animation once fetched
$('.facebookfeed').html(html);

});
});
</script>
</head>
<body onload="timeMsg()">
<div class="facebookfeed">
<h2></h2>
</div>
<script type="text/javascript">
var x =document.getElementById("tester").innerHTML;
if (x < 56700) {
document.write("worked")
}
else {
document.write("didn't work")
}
</script>
</body>
</html>

最佳答案

您需要将其放在函数中,例如:

function myFunc() {
var x =document.getElementById("tester").innerHTML;
if (x < 56700) {
document.write("worked")
}
else {
document.write("didn't work")
}
}

然后像这样调用它:

$.getJSON(url,function(json){
var html = "<div id=\"tester\">" + json.likes + "</div>";
//A little animation once fetched
$('.facebookfeed').html(html);

myFunc();
});

因为您在测试器添加到 DOM 之前执行该代码。

关于javascript - 渲染一些 JSON 后,我的 javascript 的第二部分没有执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7195310/

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