基本错误范围JQuery
如果我有一个函数,它调用index.js文件中的另一个函数。为什么要显示这个错误基本错误范围JQuery,jquery,Jquery,如果我有一个函数,它调用index.js文件中的另一个函数。为什么要显示这个错误 <!-- page js --> <script type="text/javascript" src="{{ asset('assets/js/index.js')}}" ></script> <script> function onedevice(imei) { // mostramos las graficas, se desean datos
<!-- page js -->
<script type="text/javascript" src="{{ asset('assets/js/index.js')}}" ></script>
<script>
function onedevice(imei) {
// mostramos las graficas, se desean datos
$('#charts_device1').show();
$('#charts_device2').show();
// rellenamos los datos
// var imei = $("#select_imeis").val();
if (imei !== 0) {
load_chart_device(imei); // < this line
}
}
</script>
}之所以发生这种情况,是因为函数onedevice首先执行。在html头标记中写入index.js的导入 像这样编写index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="index.js"></script>
</head>
<body>
<script type="text/javascript">
var imei = 10;
function onedevice(imei) {
// code ...
if (imei !== 0) {
load_chart_device(imei);
}
}
// call onedevice
onedevice(imei);
</script>
</body>
</html>
function load_chart_device(imei) {
console.log("load_chart_device is working fine");
alert(imei);
}
确保已在标记内导入index.js
要进一步了解其工作原理,请阅读您如何调用onedevice?load\u chart\u device在哪里定义?依我看,您的函数load\u chart\u device不在范围内。这意味着在一个设备中调用它时,它不会在任何地方定义。你是自己定义这个函数,还是一些外部代码?嗨。我在index.js中调用load\u chart\u设备。我在html中调用onedevice,$document.readyfunction{onedevice{{{$device->imei};};我将调用更改为onedevice,并将文件放在文档的开头,但不起作用。
function load_chart_device(imei) {
console.log("load_chart_device is working fine");
alert(imei);
}