Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jquery - Wait for .load to finish and then do something

I'm loading an external script through .load('url') and need to wait for it to finish so I can update the source of an image. Sometimes load is fast enough that the image reload applies, but most of the time it takes too long and the image reload happens first, so the image doesn't actually change.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add a callback function:

$('#yourElement').load('yourUrl.html', function() {
  /* When load is done */
});

More to read at http://api.jquery.com/load


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...