开发者

Is there a NotReadyFunction in jQuery?

开发者 https://www.devze.com 2022-12-18 22:26 出处:网络
Is it possible to check if the document is not ready and execute a function periodically in jQuery? Simply I would like to achieve something like :

Is it possible to check if the document is not ready and execute a function periodically in jQuery?

Simply I would like to achieve something like :

$('document').isNotReady(function(){

    $('#divState').text('Still Loading');  
});

$('document').Ready(function(){

    $('#divState').text('Loaded');
});

Is there a built-in functio开发者_开发技巧n in jQuery to achieve something like this?


You can just append the div at the top of the page with the loading text and when the document is ready change the text to loaded.

Edit

As @James pointed out, there is a problem with your selector. You are using divState as a tag selector, which won't be valid. Either you can use an id selector or a class selector in this case like

$("#divState") or $(".divState")

$(function(){
    $('#divState').text('Loaded');
});


HTML part:

<input type="button" onclick="example_ajax_request()" value="Click Me!" />
<div id="example-placeholder">
  <p>Placeholding text</p>
</div>

jQuery part:

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");
}

Source: http://www.electrictoolbox.com/load-content-jquery-ajax-loading-image/


Not as far as I am aware. You could easily immidate it though:

var bIsReady = false;

$('document').Ready(function(){ 
    bIsReady = true;
    $('divState').text('Loaded'); 
}); 

/*
    use bIsReady somehow
/*

But I'm not sure why you would want to when you could just set it in the HTML:

<div>Still Loading</div>

And then change it as per your code above when the document is ready.

Also, if there was some NotReady function, you couldn't guarantee that the DIV you were setting was actually ready.

Also, you are selecting an element called DivState. Do you maybe mean: $('#DivState') ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号