To introduce new JS includes to pages loaded (via AJAX) with jQuery Mobile you must have the references to those files within the data-role="page"
or (data-role="dialog"
) elements of each page because jQuery Mobile does not process anything outside of those elements during AJAX page loads.
Alternatively, you could use JavaScript to create the new script
tags dynamically on the 'pageshow' event of each page transition. Something like this:
$(document).on('pageshow', 'div[data-role*="page"],div[data-role*="dialog"]', function () {
(function () {
var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
script.src = '/path/to/new/include.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
})();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…