出于某种原因,我遇到了这个'
如您所见,我想尝试阅读count.txt。这是完美的,但由于某种原因
alert(code);
后
对我来说没有任何意义,因为我在警告之前调用警报(计数)("数字......")
在另一个警报之后调用jQuery函数(警报)的任何想法?alert("The number can't be smaler then 0");
function leftFunction() {
jQuery.get('count.txt', function(data) {
var count = data;
alert(count);
});
scrolling = true;
if(number == 0) {
alert("The number can't be smaler then 0");
return;
}
number--;
document.getElementById("myImage").src = "latest" + number + ".jpg";
}
答案 0 :(得分:3)
正如Red fx在评论中所说,它与JavaScript的异步相关。尝试这样的事情:
function leftFunction() {
jQuery.get('count.txt', function(data) {
var count = data;
alert(count);
}).done(function() {
scrolling = true;
if (number == 0) {
alert("The number can't be smaler then 0");
return;
}
});
number--;
document.getElementById("myImage").src = "latest" + number + ".jpg";
}