Javascript Jquery在一秒钟后隐藏gif
我尝试在一秒钟后隐藏gif图像:Javascript Jquery在一秒钟后隐藏gif,javascript,jquery,html,Javascript,Jquery,Html,我尝试在一秒钟后隐藏gif图像: $('input.sortInp').change(function () { $(this).parents('.float_left').find('.sortLoaderDiv').html('<img class="sortLoader" src="/images/icons/loading_small1.gif">'); setTimeout(function () { $(this).parents('.float_l
$('input.sortInp').change(function () {
$(this).parents('.float_left').find('.sortLoaderDiv').html('<img class="sortLoader" src="/images/icons/loading_small1.gif">');
setTimeout(function () {
$(this).parents('.float_left').find('.sortLoaderDiv').html("Some text");
},1000);
});
$('input.sortInp').change(函数(){
$(this.parents('.float_left').find('.sortLoaderDiv').html('');
setTimeout(函数(){
$(this).parents('.float_left').find('.sortLoaderDiv').html(“一些文本”);
},1000);
});
我看到了我的gif,但它没有隐藏在我的setTimeout
函数中如何停止此gif并替换div文本?谢谢。试试这个
$('input.sortInp').change(function () {
var input = $(this);
input.parents('.float_left').find('.sortLoaderDiv').html('<img
class="sortLoader" src="/images/icons/loading_small1.gif">');
setTimeout(function () {
input.parents('.float_left').find('.sortLoaderDiv').html("Some text");
}, 1000);
});
$('input.sortInp').change(函数(){
var输入=$(此);
input.parents('.float_left').find('.sortLoaderDiv').html('');
setTimeout(函数(){
input.parents('.float_left').find('.sortLoaderDiv').html(“一些文本”);
}, 1000);
});
试试这个
$('input.sortInp').change(function () {
var input = $(this);
input.parents('.float_left').find('.sortLoaderDiv').html('<img
class="sortLoader" src="/images/icons/loading_small1.gif">');
setTimeout(function () {
input.parents('.float_left').find('.sortLoaderDiv').html("Some text");
}, 1000);
});
$('input.sortInp').change(函数(){
var输入=$(此);
input.parents('.float_left').find('.sortLoaderDiv').html('');
setTimeout(函数(){
input.parents('.float_left').find('.sortLoaderDiv').html(“一些文本”);
}, 1000);
});
我能想到的最佳解决方案是使用闭包变量
问题是:对setTimeout()
的回调与主线程分开执行
回调的执行上下文将不同,因此回调内部的对象与setTimeout外部的对象不相同,在本例中为悬停的.sortInp
元素
$('input.sortInp').change(函数(){
$(this.parents('.float_left').find('.sortLoaderDiv').html('');
var self=$(这是);
setTimeout(函数(){
self.parents('.float_left').find('.sortLoaderDiv').html(“一些文本”);
},1000);
});代码>
我能想到的最佳解决方案是使用闭包变量
问题是:对setTimeout()
的回调与主线程分开执行
回调的执行上下文将不同,因此回调内部的对象与setTimeout外部的对象不相同,在本例中为悬停的.sortInp
元素
$('input.sortInp').change(函数(){
$(this.parents('.float_left').find('.sortLoaderDiv').html('');
var self=$(这是);
setTimeout(函数(){
self.parents('.float_left').find('.sortLoaderDiv').html(“一些文本”);
},1000);
});代码>
当您给出html()
时,中的所有代码都会消失。因此,您的输入input.sortInp
也将消失。因此jQuery无法在setTimeout函数中找到输入input.sortInp
。这是因为您选择了选择器的父类。请更正您的代码,以便input.sortInp
不会被html()
方法擦除。或者,试试这个
$('input.sortInp').change(function () {
$('.sortLoaderDiv').html('<img
class="sortLoader" src="/images/icons/loading_small1.gif">');
setTimeout(function () {
$('.sortLoaderDiv').html("Some text");
},1000);
}
$('input.sortInp').change(函数(){
$('.sortLoaderDiv').html('');
setTimeout(函数(){
$('.sortLoaderDiv').html(“一些文本”);
},1000);
}
当你给出html()时
sortLoaderDiv
中的所有代码都会消失。因此您的输入input.sortInp
也会消失。因此jQuery无法在setTimeout函数中找到输入input.sortInp
。发生这种情况是因为您选择了选择器的父类。请更正您的代码,以便input.sortInp
不会被html()
方法擦除。否则,请尝试此操作
$('input.sortInp').change(function () {
$('.sortLoaderDiv').html('<img
class="sortLoader" src="/images/icons/loading_small1.gif">');
setTimeout(function () {
$('.sortLoaderDiv').html("Some text");
},1000);
}
$('input.sortInp').change(函数(){
$('.sortLoaderDiv').html('');
setTimeout(函数(){
$('.sortLoaderDiv').html(“一些文本”);
},1000);
}
试试这个:$(this).parents('.float_left').find('.sortLoaderDiv').hide();
在setTimeout函数中。$(this)
在你的setTimeout
函数中不起作用。你必须在该函数之外为$(this)
定义一个变量。谢谢,定义了$(this)它就可以工作了!试试这个:$(this).parents('.float_left')。在setTimeout函数中查找('.sortLoaderDiv').hide();
。setTimeout
函数中的$(此)
不起作用。您必须在该函数之外为$(此)
定义一个变量。谢谢,定义了$(此)
,它起作用了!