Javascript SystemJS:jquery_1.$不是函数
我正在学习systemjs和整个ES6模块,并将其移植到较旧的浏览器 作为一篇教育性文章,我尝试加载jquery并使用Javascript SystemJS:jquery_1.$不是函数,javascript,jquery,systemjs,Javascript,Jquery,Systemjs,我正在学习systemjs和整个ES6模块,并将其移植到较旧的浏览器 作为一篇教育性文章,我尝试加载jquery并使用alert() 现在,我让systemjs运行到加载typescript和jquery的地步,但在页面加载几秒钟后失败,出现以下错误: Error: (SystemJS) jquery_1.$ is not a function TypeError: jquery_1.$ is not a function at execute (http://local
alert()
现在,我让systemjs运行到加载typescript和jquery的地步,但在页面加载几秒钟后失败,出现以下错误:
Error: (SystemJS) jquery_1.$ is not a function
TypeError: jquery_1.$ is not a function
at execute (http://localhost/webpMain/main.js!transpiled:12:22)
Error loading http://localhost/webpMain/main.js
at execute (http://localhost/webpMain/main.js!transpiled:12:22)
Error loading http://localhost/webpMain/main.js
该页面只是一个巨大的红色框,如果点击它,它应该只是提醒“Hello world”
这是标记:
<!DOCTYPE html>
<html lang="us">
<head>
<title>SystemJS Test</title>
<script src="node_modules\systemjs\dist\system.js"></script>
<script src="system.config.js"></script>
<style>
#box {
width: 300px;
height: 300px;
position: absolute;
background: red;
}
</style>
</head>
<body>
<div id="box"></div>
</body>
<script>
System.import("app")
.catch(function(err) {
console.log(err);
});
</script>
</html>
和main.js
import { $ } from "jquery";
$("box").click(function() {
alert("Hello world!!");
});
- 你知道为什么jquery导入不起作用吗李>
- typescript或systemjs显示的错误是什么
import $ from "jquery";
$("box").click(function() {
alert("Hello world!!");
});
jQuery不会导出任何名为$
的内容
另外,由于您使用的是TypeScript,因此包配置应该如下所示
packages: {
app: {
main: 'main.ts',
defaultExtension: 'ts'
}
}
当前正在传输两次。$(“框”)。单击(函数(){alert(“Hello world!!”);});我认为应该是:
$(“#box”)
,因为box是一个id。我从来没有使用过systemjs,所以我不确定如果没有,这不应该是一个问题,如果选择器错误,那么什么都不应该发生,不应该发生错误。对。选择器是个问题,但是。。。这不是问题的重点,这有关系吗?这里还有一个:
packages: {
app: {
main: 'main.ts',
defaultExtension: 'ts'
}
}