开发者

attaching handlers to virtual controls in jQuery

开发者 https://www.devze.com 2023-01-15 06:16 出处:网络
Here is what i\'m trying to accomplish.... I need to be able to register elements that aren\'t part of the DOM when they are created.

Here is what i'm trying to accomplish....

I need to be able to register elements that aren't part of the DOM when they are created.

here is the syntax i'm trying to synthesize

$(document).ready(function(){

   $('#virtualControl').registerControl(function(){ alert('do someth开发者_运维知识库ing'); });

   // simulate adding the control to the dom
   $('#virtualControls').append($("<a id='virtualControl'>Virtual</a>"));

   $(document).trigger('render'); // at this point it should call the fn that was passed in to the 'register control' function

});


This is similar to what the .livequery() plugin does, you can use it like this:

$("selector").livequery(function() {
  //this runs when an element found, or added later
});

The function you pass runs for every element added later, which seems to be what you're after.

0

精彩评论

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