We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

概述

返回其所包含的脚本中正在被执行的 <script> 元素.

语法

var curScriptElement = document.currentScript;

示例

下例演示了如何检测当前正在执行脚本的 <script> 元素是否是以异步模式执行的.

if (document.currentScript.async) {
  console.log("Executing asynchronously");
} else {
  console.log("Executing synchronously");
}

查看在线演示

附注

值得注意的是,如果当前正在执行的代码是处在某个回调函数或者事件处理函数中的,那么 currentScript 属性不会指向包含那个函数的 <script> 元素,而是会返回 null.

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 29 4.0 (2.0) ? ?
?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? yes ? ? ?

规范

相关链接

文档标签和贡献者

标签: 
此页面的贡献者: zhaoqize, teoli, khalid32, ziyunfei, zhangyaochun1987
最后编辑者: zhaoqize,