script type="module" 里边的函数怎么调用不到呢?
javascript吧
全部回复
仅看楼主
level 2
js小白问个问题
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
</head>
<body>
<!-- Note the usage of `type=module` here as this is an ES6 module -->
<script type="module">
function clk()
{
console.log(add(100, 200));
}
</script>
<input type=button value="按钮" onclick="clk()">
</body>
</html>
2019年04月12日 18点04分 1
level 4
没暴露,当然用不了
2019年04月13日 11点04分 2
怎么暴露呢?我学的js还停留在n年前.
2019年04月13日 13点04分
如果忙的话请指点给链接也行。再不济赏赐个 搜索的关键字吧。超级感谢。
2019年04月13日 14点04分
@命运那条线 不是没暴露,是因为module可以看作是异步的,所以下面的script开始执行时,上面的还没有运行,所以module里面的变量都拿不到。
2020年01月19日 08点01分
如果想要拿到变量,可以在下面的script标签后面加一个属性deffer,代表js异步执行。
2020年01月19日 08点01分
level 11
add()这个方法好像是jquery的吧,而且用法也不是这样的...[黑线]
2019年04月16日 07点04分 3
level 7
没exporr
2019年05月02日 10点05分 4
不是没暴露,是因为module可以看作是异步的,所以下面的script开始执行时,上面的还没有运行,所以module里面的变量都拿不到。只有import的变量才需要export
2020年01月19日 08点01分
level 1
这个需要 在 type=“module" 的js 中 export 出你需要暴露的函数,然后在调用,你把这个 script 定义为 模块了,应该去掉那个 type ,完全没有必要
2019年08月20日 10点08分 5
我export函数但是按钮无法调用函数,报错说未定义
2019年11月14日 02点11分
不是没暴露,是因为module可以看作是异步的,所以下面的script开始执行时,上面的还没有运行,所以module里面的变量都拿不到。只有import的变量才需要export
2020年01月19日 08点01分
level 1
文档自上而下执行 script 放 <body> 下面
或者包在 window.onload = function(){ ... }
2020年05月04日 15点05分 6
level 6
1、你如果只是想调用函数,没必要在script标签上加上type=module
2、再
看看你的
add方法哪来的?
2020年05月05日 09点05分 7
level 1
因为模块里的变量不会声明为全局变量,类似于
<script type=m..>
(function(){
//你的代码
})
</script>
2020年05月21日 11点05分 8
level 1
你要是导出的话,如果使用的话就要引入,然后在引入的方法块中,仍然执行不到函数
2020年06月29日 02点06分 9
level 1
问题是怎么引入module,靠一堆人没给个明确说法
2020年07月18日 06点07分 11
level 1
这种是无法定义元素事件的,解决办法:给input按钮一个#brn,js获取元素,let btn = document.quertSelector("#btn"); btn.onclick = function () {console.log(add(100,200))}
2020年08月19日 03点08分 14
level 1
解决了吗?
2020年09月19日 10点09分 15
1