从外部src重新载入HTML中的脚本? [英] Reload script in HTML from outside src?

查看:88
本文介绍了从外部src重新载入HTML中的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我的HTML文件中的代码如下:

Basically, I have code that looks like this in my HTML files:

<script src="http://somelink.something/file.extension"></script>
<script src="http://somedifferentlink.something/file.extension"></script>
<script src="http://therearelotsofthesethings.something/file.extension"></script>
<script src="http://ineedallofthesetohappeneverytimeacertaineventhappens.something/file.extension"></script>

我想具体地知道每当按下某个按钮时如何从这种脚本中重新执行代码.除了这件事之外,我还具有对按钮功能进行完全编程的功能,但是此脚本调用外部链接来对所有内容进行专门格式化,因此我需要在按下按钮时进行相应的设置.有没有简单的方法可以做到这一点?

I want to know specifically how to re-execute code from this kind of script whenever a certain button is pressed. I have the functionality of the button fully programmed outside of this one thing, but this script calls on outside links to specifically format everything nicely, and I need that to happen whenever the button is pressed. Is there a simple way of doing this?

是的,我尝试查找内容,但是找不到确切的查询,也找不到能回答该查询的任何内容.

Yes, I tried looking things up, but I couldn't find this exact query, nor anything that would answer it.

编辑:这些文件大多是.js文件,尽管不是全部.按下按钮时执行的代码完全写在JavaScript中.

These are mostly .js files, though not all of them are. The code that executes when the button is pressed is written entirely in JavaScript.

推荐答案

这是我的工作代码.我使用jQuery作为脚本.在您的onclick button event:

Here is my working code. I used jQuery as my script. Use this lines inside your onclick button event:

var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'jquery.min.js');
document.head.appendChild(script);

然后就可以了.

更多信息.当您执行script.type = 'text/javascript'之类的操作时,您正在对象上设置属性,但这与将该属性与实际的节点属性相关联不一定是同一件事.

Some more info. When you do something like script.type = 'text/javascript' you are setting a property on the object but this is not necessarily the same thing as associating that property with an actual node attribute.

这篇关于从外部src重新载入HTML中的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆