Javascript jQuery中有NotReadyFunction吗?
是否可以检查文档是否未准备好,并在jQuery中定期执行函数 我只想实现以下目标:Javascript jQuery中有NotReadyFunction吗?,javascript,jquery,document-ready,ready,Javascript,Jquery,Document Ready,Ready,是否可以检查文档是否未准备好,并在jQuery中定期执行函数 我只想实现以下目标: $('document').isNotReady(function(){ $('#divState').text('Still Loading'); }); $('document').Ready(function(){ $('#divState').text('Loaded'); }); jQuery中是否有一个内置函数来实现类似的功能?您只需在页面顶部添加加载文本的div,然后在文
$('document').isNotReady(function(){
$('#divState').text('Still Loading');
});
$('document').Ready(function(){
$('#divState').text('Loaded');
});
jQuery中是否有一个内置函数来实现类似的功能?您只需在页面顶部添加加载文本的div,然后在文档准备就绪时将文本更改为加载 编辑 正如@James指出的,您的选择器存在问题。您正在使用divState作为标记选择器,这将无效。在这种情况下,您可以使用id选择器或类选择器,如
$(“#divState”)
或$(“.divState”)
据我所知不是这样。不过,您可以很容易地将其移入:
var bIsReady = false;
$('document').Ready(function(){
bIsReady = true;
$('divState').text('Loaded');
});
/*
use bIsReady somehow
/*
但我不确定您为什么要在HTML中设置它:
<div>Still Loading</div>
仍在加载
然后在文档准备好后,按照上面的代码进行更改
此外,如果有一些NotReady函数,则无法保证所设置的DIV实际上已准备就绪
另外,您正在选择一个名为DivState的元素。你的意思是:
$(“#DivState”)
?HTML部分:
<input type="button" onclick="example_ajax_request()" value="Click Me!" />
<div id="example-placeholder">
<p>Placeholding text</p>
</div>
function example_ajax_request() {
$('#example-placeholder').html('<p><img src="/images/ajax-loader.gif" width="220" height="19" /></p>');
$('#example-placeholder').load("/examples/ajax-loaded.html");
}
占位符文本
jQuery部分:
<input type="button" onclick="example_ajax_request()" value="Click Me!" />
<div id="example-placeholder">
<p>Placeholding text</p>
</div>
function example_ajax_request() {
$('#example-placeholder').html('<p><img src="/images/ajax-loader.gif" width="220" height="19" /></p>');
$('#example-placeholder').load("/examples/ajax-loaded.html");
}
函数示例\u ajax\u请求(){
$(“#示例占位符”).html(“”);
$('#示例占位符').load(“/examples/ajax-load.html”);
}
来源:+!换个角度想想!