gpt4 book ai didi

Javascript/jQuery 更改正文中的脚本 src 并刷新

转载 作者:太空宇宙 更新时间:2023-11-04 16:25:16 25 4
gpt4 key购买 nike

我有一个脚本,需要在运行时更改并重新加载更改

所以脚本是:

<body>
<script id="scriptId" src="myJsFile_1.js"></script>

//Rest of the page here


<script>

$(document).ready(function() {

$("#buttonId").click(function() {

//Change the script src to myJsFile_2.js and reload

})

});

</script>

</body>
</html>

我该怎么做?

最佳答案

用这个

$(document).ready(function() {
$("#buttonId").click(function() {

$(document.body).remove('#scriptId').append('<script id="scriptId" type="text/javascript" src="your_script_src"></script>');

});
});

关于Javascript/jQuery 更改正文中的脚本 src 并刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40285767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com