开发者

JQuery executing onLoad

开发者 https://www.devze.com 2022-12-13 11:16 出处:网络
So I\'m trying to execute a function on a component when the page loads.This is what I have so far. $(document).ready(function() {

So I'm trying to execute a function on a component when the page loads. This is what I have so far.

$(document).ready(function() {
  var $foo = $('#data_lost').hide();

  $f = function () {
    doSomething...
  };

  $foo.change($f);
});

So this all works fi开发者_StackOverflowne and dandy. Here's the problem. I also need $f executed on $foo when the page loads. I tried setting $foo.ready($f), but that doesn't work. I tried setting it inside and outside of document.ready(). Neither options work. I'm assuming that doing it outside doesn't work because the tag doesn't exist until document is ready, and doing it inside doesn't work because when the document is ready, the tag has already become ready, so it won't ever be ready again, so $f isn't called.

Ideas??

TIA!


You can just do $f(); inside the ready block to execute your function on page load.


Well, goes to show...you ask...fate has it that you find your own answer soon after...

added:

$foo.change();

after $foo.change($f).

0

精彩评论

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