admin管理员组

文章数量:1336199

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.

Can somebody please explain how exactly (or link me from a known real example), can we make javascripts working on a Laravel project ? Thanks

Here's what i tried :

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

@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

$('#popoverData').popover();
$('#popoverOption').popover({ trigger: "hover" })

Where are my js files ?

/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 : /

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.

Can somebody please explain how exactly (or link me from a known real example), can we make javascripts working on a Laravel project ? Thanks

Here's what i tried :

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

@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

$('#popoverData').popover();
$('#popoverOption').popover({ trigger: "hover" })

Where are my js files ?

/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/9P64a/

Share asked Nov 7, 2014 at 12:58 Gui OGui O 3834 gold badges10 silver badges22 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

You should put your javascript in a document ready function. You javascript code won't work because the document isn't fully loaded yet.

change the javascript code to the following:

$(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.

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 menting out

app.js

asset.

本文标签: jqueryLaraveljavascript not working but no errorStack Overflow