Laravel - javascript 不工作但没有错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26801780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel - javascript not working but no error
提问by Gui O
I am now trying to use javascripts in my project. I searched all this morning on the Internet, and found nothing really clear about Laravel and Javascript.
我现在试图在我的项目中使用 javascripts。我今天早上在互联网上搜索了所有内容,没有发现关于 Laravel 和 Javascript 的任何内容。
Can somebody please explain how exactly(or link me from a known real example), can we make javascriptsworking on a Laravel project ? Thanks
有人可以解释一下(或从已知的真实示例中链接我),我们可以让javascripts在 Laravel 项目上工作吗?谢谢
Here's what i tried :
这是我尝试过的:
template_mynet.blade.php
template_mynet.blade.php
...
{{ HTML::script('assets/js/jquery-2.1.1.js') }}
{{ HTML::script('assets/js/bootstrap.min.js') }}
{{ HTML::script('assets/js/bootstrap.js') }}
{{ HTML::script('assets/js/accueil_hover.js') }}
...
accueil.blade.php
accueil.blade.php
@extends('template_mynet')
@section('content')
<div class="container">
<a id="popoverData" class="btn" href="#" data-content="Popover with data-trigger" rel="popover" data-placement="bottom" data-original-title="Title" data-trigger="hover">Popover with data-trigger</a>
<a id="popoverOption" class="btn" href="#" data-content="Popup with option trigger" rel="popover" data-placement="bottom" data-original-title="Title">Popup with option trigger</a>
</div>
@stop
accueil_hover.js
accueil_hover.js
$('#popoverData').popover();
$('#popoverOption').popover({ trigger: "hover" })
Where are my js files ?
我的 js 文件在哪里?
/public/assets/js
What are my files ?
我的文件是什么?
accueil_hover.js
bootstrap.js
bootstrap.min.js
jquery-2-1-1.js
npm.js
Links are here, but the hovering is not working ! This code is from the example linked here : http://jsfiddle.net/9P64a/
链接在这里,但悬停不起作用!此代码来自此处链接的示例:http: //jsfiddle.net/9P64a/
回答by Jerodev
You should put your javascript in a document ready function. You javascript code won't work because the document isn't fully loaded yet.
您应该将您的 javascript 放在文档就绪函数中。您的 javascript 代码将无法工作,因为文档尚未完全加载。
change the javascript code to the following:
将 javascript 代码更改为以下内容:
$(document).ready(function(){
$('#popoverData').popover();
$('#popoverOption').popover({ trigger: "hover" });
});
If this is still not working, please provide the full html output of your site and any console errors.
如果这仍然不起作用,请提供您站点的完整 html 输出和任何控制台错误。
回答by sajed zarrinpour
I had a weird problem though. The title of the question is the exact same thing but I had document ready function. The culprit was something else and it fixed by commenting out
不过我遇到了一个奇怪的问题。问题的标题是完全一样的,但我有文档准备功能。罪魁祸首是别的东西,它通过注释掉了
app.js
应用程序.js
asset.
资产。