开发者

Grab a script and reload it ? jQuery

开发者 https://www.devze.com 2023-03-23 13:26 出处:网络
I have the following: <div id=\"some-id\"></div><script src=\"/script.js\" type=\"text/javascript\">

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消