Ajax asynchronously loads some pages (target-page). a button exists in the target-page, and you want to set an onclick function for the button. However, the trigger logic is always unavailable: front-end jqueryload () (ajax asynchronous) load the page, btn put the pseudo code in the target-page... ajax asynchronously loads some pages (target-page). a button exists in the target-page and you want to set an onclick function for the button.
Unable to trigger
Logic: front-end jqueryload()(Ajax asynchronous) load pages, btn placed in target-page
The pseudocode is as follows: (if the code is too long, it will be replaced with the pseudo code)
Ajax. js:
$ (Function () {$ (xxx ). load (target-page); function a () {codes} setTimeout (function () {$ (btn ). click (a); // use settimeout to solve}, 0 );});
Can someone help me explain the principles and correct solutions ??
I personally think that the problem is that it is triggered after the basic js content (variable/function declaration) is loaded asynchronously, and the elements cannot be obtained.
Reply content:
Ajax asynchronously loads some pages (target-page). a button exists in the target-page and you want to set an onclick function for the button.Unable to trigger
Logic: front-end jqueryload()(Ajax asynchronous) load pages, btn placed in target-page
The pseudocode is as follows: (if the code is too long, it will be replaced with the pseudo code)
Ajax. js:
$ (Function () {$ (xxx ). load (target-page); function a () {codes} setTimeout (function () {$ (btn ). click (a); // use settimeout to solve}, 0 );});
Can someone help me explain the principles and correct solutions ??
I personally think that the problem is that it is triggered after the basic js content (variable/function declaration) is loaded asynchronously, and the elements cannot be obtained.
Take a look at the document: http://api.jquery.com/load/
In addition,target-pageIt's not a variable. what is it?
Reference Code
// The second parameter is data. null is not directly given, or {} // you can omit the example in the document and use callback as the second parameter $ (xxx ). load (url, function () {// do callback here });