JavaScript script files are loaded at the bottom of the page to effectively speed up the load on the page.
However, the PHP controller generally writes this:
Copy Code code as follows:
$this->load->view ($HEADER);
$this->load->view ($MENU);
$this->load->view ($VIEW _show, $data);
$this->load->view ($FOOTER);
$FOOTER is a common template for loading JS and CSS files.
$VIEW _show As the main template, you may want to write some of the JS code, which usually need to use the resources of public files, the JS write to the back of the $footer is inconvenient, jquery $ (document). Ready can't use it. At this time, with the window.onload can be, as follows:
Copy Code code as follows:
Window.onload = function () {
(function ($) {
function test () {alert (123);}
or write some binding based on jquery or something.
}) (JQuery)
};
But if you want to window.onload from the inside, like you want to call Parent.test () in the Sub iframe of this window, there is no result.
At this point, you can work around the function as a global variable.
Copy Code code as follows:
var test; Declaration of global Scope
Window.onload = function () {
(function ($) {
Test = function () {alert (123);};
or write some binding based on jquery or something.
}) (JQuery)
};
It is safer to change a private function to a global one only when it is needed.