javascript - 如何使用 JavaScript 禁用 <script> 元素

标签 javascript dom

我想禁用 <script>标签。这是我的代码,但它不起作用。

document.getElementsByTagName('script').disabled = true;

最佳答案

事实上,可以通过改变“type”属性来禁止执行:

<script type="text/javascript">
    alert("I will alert you");
</script>

<script type="application/json">
    alert("And I will keep silent");
</script>

<script>
    alert("I will alert too");
</script>

http://jsfiddle.net/r6c0x0sc/

关于javascript - 如何使用 JavaScript 禁用 &lt;script&gt; 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9850317/

相关文章:

dom - 无法操作 React 组件中的 DOM

javascript - 使用 CasperJS 中的函数返回 iframe 内的链接

javascript - 为什么当我 console.log 我的测试区 block 链时 previousHash 没有显示?

javascript - 简讯 |传递默认设置 |函数声明和 'this'

jquery - 如何使用 jquery 将某些内容附加到空主体

html - Visual Studio Code : how to automatically change the matching closing tag

javascript - 强制门户上的权限弹出窗口

javascript - 删除包装的事件处理程序

javascript - 在使用 angularjs 指令渲染之前从 DOM 中删除元素

java - 如何将新节点附加到现有 xml 文件