I have the following:
<div id="some-id"></div><script src="/script.js" type="text/javascript">
I'm trying to basically use the some-id
to grab the script and reload it ? How would I do this via ajax ?
i.e. l开发者_如何学Pythonike
var scriptLoad = jQuery('#some-id').next().attr('src');
Then reload the src
Get the next sibling, load the source path, append a querystring to clear any cache. (changing the src causes the script to reload)
var sc = $("#some-id").next();
var src = sc.attr("src");
sc.attr("src", (sc.indexOf("?") == -1 ? "?" : "&") + "c=" + Math.random());
Try this, it will reload the script tag in the head tag of the page.
$("head").append($("#some-id").find("script:first"));
<div id="some-id"></div>
<script id="my-script" src="/script.js" type="text/javascript">
$('#my-script').setAttribute("src", "/script.js");
Try this:
jQuery('#some-id').next().clone().appendTo(document.body);
精彩评论