[英]$ is not defined while using DataTables in jQuery
I am trying to use datatables but an error is coming我正在尝试使用数据表,但出现错误
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$('#myTable').DataTable(); // I am getting error on this line
});
</script>
Note - The id given ('#myTable') is absolutely correct and there is no issue related with it注意 - 给定的 id ('#myTable') 是绝对正确的,没有与之相关的问题
You can find here https://datatables.net/manual/index the following information:您可以在https://datatables.net/manual/index找到以下信息:
Compatibility information: DataTables 1.10+ and its extensions require with jQuery 1.7 or newer.
兼容性信息: DataTables 1.10+ 及其扩展需要 jQuery 1.7 或更高版本。
In your case you have to satisfy jquery.dataTables dependency to jquery by including jquery in the first place.在您的情况下,您必须首先包含 jquery 来满足 jquery.dataTables 对 jquery 的依赖性。 This code below works without the described error.
下面的代码在没有描述的错误的情况下工作。
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script> <script> $(document).ready(function() { // Error is gone now because dataTables dependency to // Jquery is satisfied. $('#myTable').DataTable(); }); </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.