我想在我的项目中使用RequireJs,但是我发现我不能写代码如下如果我使用RequireJs,所有js函数都需要.js文件吗?
<html>
<head>
</head>
<body>
<input type="button" />
<script>
// Use the jQuery
$(function() {
//some code
}
)
</script>
<input />
<input />
// I had added the jQuery in required shim and jQuery is working in RequireJs.
<script data-main="scripts/main" src="/scripts/require.js"></script>
</body>
</html>
出现错误$ is undefined
,加载页面时。 我抬头看了很多文章,但我解决不了。我该如何处理?我不想将示例js函数移动到.js文件。
include – user2361114
否则包含在头部分 – user2361114
如果您不打算在头部脚本标记中使用jQuery,那么您只需要$(document).ready事件侦听器。 然后你可以做'document.addEventListener('DOMContentLoaded',function(){//一些代码})' 如果你想支持