for example if i write this code :
$(document).ready(function(){
$("div#i").click(function(){
alert("ok");
});
});
and the div element with the i id is not found in the page when load , so after i create it with some function ; and i click it , nothing happen , so how i can refresh the ready function in jquery ..
调查使用.live()
: http : //api.jquery.com/live/
Take that click event handler out of (document).ready and place it in the function that you've mentioned which creates the ID.
function someFunction()
{
//creates the id, then
$("div#i").click(function(){
alert("ok");
});
}
EDIT:
If this is just one example among many potential event handlers, then wrap them all in a single function, say, bindEvents()
and you can call that every time the page is 'dirtied' by an ID creation.
But the other commenters' approach of using .live() will probably be less to maintain, and it's "the JQuery way" if that's a concern for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.