我有laravel布局
<html> //layout.blade.php
<head>
<script src="/js/jquery.js"></script>
<script src="/js/jquery-ui.js"></script>
</head>
<body>
@yield("content")
</body>
</html>
我的观点
@extends("layout")
@section("content")
<ul class="test">
<li>1</li>
<li>2</li>
</ul>
<script>
$(function() {
$(".test").selectable();
});
</script>
@endsection
我的浏览器控制台总是向我显示$(...)。selectable不是函数
但是如果我在没有布局或没有匿名功能的情况下做到这一点
答案 0 :(得分:2)
我认为位置因路线而异。 因此,最好指定“ public”文件夹的正确网址。
请这样更改。
<html> //layout.blade.php
<head>
<script src="{{URL::Asset('/js/jquery.js')}}"></script>
<script src="{{URL::Asset('/js/jquery-ui.js')}}"></script>
</head>
<body>
@yield("content")
</body>
</html>
答案 1 :(得分:0)
如上一个问题所述,当您尝试传递参数或路由变量时,通常会出现这种问题。因此,在使用页面中的资源时,最好使用asset()
或secure_asset()
。
<html> //layout.blade.php
<head>
<script src="{{ asset('js/jquery.js') }}"></script>
<script src="{{ asset('js/jquery-ui.js') }}"></script>
</head>
<body>
@yield("content")
</body>
</html>
还请检查浏览器的网络部分,以确保您的资源加载正常。