[英]Script doesn't work after combining 2 different scripts in one blade.php file (laravel)
I wanted to combine 2 script from different sources into one blade.php file in laravel as some contents need to use different script respectively.我想将来自不同来源的 2 个脚本合并到一个刀片中。laravel 中的 php 文件,因为某些内容需要分别使用不同的脚本。 The 2 scripts are like this:
2个脚本是这样的:
1st script:第一个脚本:
<script src="{{ asset('js/app.js') }}"></script>
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'article-ckeditor' );
</script>
2nd script:第二个脚本:
<script type="text/javascript">
$('.itemName').select2({
placeholder: 'Select state',
ajax: {
url: '/select2-autocomplete-ajax',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.name,
id: item.id
}
})
};
},
cache: true
}
});
</script>
This is how I combined above scripts.这就是我组合上述脚本的方式。 Simply just copy the 2nd script at below of the first script:
只需复制第一个脚本下方的第二个脚本即可:
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'article-ckeditor' );
</script>
<script type="text/javascript">
$('.itemName').select2({
placeholder: 'Select state',
ajax: {
url: '/select2-autocomplete-ajax',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.name,
id: item.id
}
})
};
},
cache: true
}
});
</script>
However, when I compiled, it doesn't worked as I expected because one of the scripts doesn't function.但是,当我编译时,它没有按预期工作,因为其中一个脚本不是 function。 How should I compile two scripts in one file?
我应该如何在一个文件中编译两个脚本?
Try it without type="text/javascript"
on last script tag.在最后一个脚本标签上不带
type="text/javascript"
试试。 I don't know the logic behind it, but in some cases it has worked for me.我不知道它背后的逻辑,但在某些情况下它对我有用。
<script >
$('.itemName').select2({
placeholder: 'Select state',
ajax: {
url: '/select2-autocomplete-ajax',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.name,
id: item.id
}
})
};
},
cache: true
}
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.